I am trying to insert into my database from 2 AsyncTask
s.
I have only one static instance of my SQLiteDatabase
object, both AsyncTask
s are executed with a SerialExecutor
, when I am starting both DB transactions I am passing in a SQLiteTransactionListener
and the onCommit
callback is called for both inserts (I have tried using beginTransactionWithListenerNonExclusive()
and beginTransactionWithListener()
), and still the second insert fails to write into my db (no exceptions nothing indicating that it has failed).
Basically, I have an AsyncTaskLoader
and in its onLoadFinished
, I read my JSON and after that I fire the first AsyncTask
where I start inserting into my DB, as this goes along there is a button that fetches me a list and populates a ListView
of data from the same table where the first asyncTask
writes into.
When I click on any of the items from the ListView
, I fetch the data relevant for this selected item and insert a new entry in the same table (all of that fetching and inserting happens in a second AsyncTask
).
The onCommit
callback for the second asyncTask
insert is called and when the second asyncTask
finishes (onPostExecuted
is called), I start a new activity where I am supposed to read the newly inserted data (interesting enough, that failing to insert happens randomly).
Even though both of my AsyncTask
s are executed in serial (meaning the second one should wait for the first one to finish, right?) and the Listener
tells me that the data is inserted, only the first AsyncTask
successfully inserts the data. Why is this occurring?