I'm trying to do a custom calendar in my app with event sync with a WebService.
Everything goes just fine (well, not really).
The Calendar Activity starts an AsyncTask in order to get current month events and store them in the database and the onPostExecute method updates the view to properly mark each day.
My problem comes when the user gets to the calendar activity and then quickly goes back to main activity several times, let's say for instance
Main Activity > Calendar Activity (Press Back button) > Main Activity > Calendar Activity (Press Back button) > ...
At this point Activity freezes due to a database lock has not been available for 30 sec. or App crashes due a SQLiteConstraintException: error code 19 
EDIT:
SQLiteConstraintExceptionbehaviour no longer happens
Because being updated is very important in my app, every time I re-enter the Calendar Activity I delete the database and re-populate it with server new data even tough it is the same, and at this point is where the lock is made.
EDIT:
I've changed
Delete > Insertstyle to:Updateall data (setflagcolumn = 0) >Insertnew data (setflagcolumn = 1) >Delete(whereflagcolumn = 0)
I have already tried this solution to cancel the AsyncTask on Activity finish with no success
I am sure the problem is I don't completely understand the process of what I am doing so I am missing something really important (or basic).
Any help improving my code or just pointing me to the right direction, would be much appreciated.
Thanks in advance!
EDIT:
My application has an
Aplicationwhich is in charge of creating a single Database connection (getWriteableDatabase();) and this unique conection is reachable troughMyApp.getDatabase();method.
 
     
     
    