user1179014
user1179014

Reputation: 3

Database blocked and AsyncTask

Is there a possibilty to make a thread that is only for showing a progressdialog while a method is running, without putting the operation itself inside the thread, as it is done in AsyncTask?

Let’s say first line of method is something like startThread with something like ProgDialog.show(), last line is something like stopThread with something like ProgDialog.dismiss().

The reason I ask for that is, that I tried it with AsyncTask, and it worked well until the database-method what I called inside AsyncTask was trying to do database operations while other database operations in main UI were not yet finished (or tried to start).

So I got an exception that the database is blocked. I most often work with transactions in sqlite for consistency and performance, which is also necessary in this case.

Upvotes: 0

Views: 193

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006964

is there a possibilty to make a thread that is only for showing a progressdialog while a method is running, without putting the operation itself inside the thread, as it is done in AsyncTask? Let’s say first line of method is something like startThread with something like ProgDialog.show(), last line is something like stopThread with something like ProgDialog.dismiss().

No, because the only thread that can show and dismiss a dialog is the main application thread, and you specifically do not want to block that thread.

It worked well until the database-method what I called inside AsyncTask was trying to do database operations while other database operations in main UI were not yet finished (or tried to start).

Move the "other database operations" off the main application thread.

Upvotes: 1

Related Questions