Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite transaction is blocking Android ui

In my android app there is a relatively long running AsyncTask I'm running to update the database when the app starts up. I'm needing to wrap that in a transaction to roll things back if the user exits the app before the task is finished. However since wrapping the code in a transaction it is blocking the ui untill the task is complete. Why would this be since the code is already running in a separate thread?

I'm using ORMLite and this is the wrapper for the transaction basically,the code to update the db goes inside call().., before adding the code to update the db inside a transaction there was no locking of the ui...

public ConnectionSource source; 
@Override
protected Boolean doInBackground(Context... params) {
    try {
        TransactionManager.callInTransaction(source, new Callable<Void>() {
            public Void call() throws Exception {
                return null;
            }
        });
like image 502
TNM Avatar asked Oct 25 '11 13:10

TNM


1 Answers

Unfortunately, SQLite transactions are exclusive and they block all other database activity. I suspect that even though you are in another thread, the UI thread is doing some sort of database activity which has to wait for the transaction to finish.

  • Here's a related question.
  • Here's the docs about SQLite transaction levels.
like image 139
Gray Avatar answered Sep 27 '22 22:09

Gray