user1709805
user1709805

Reputation: 2038

Android: Dialog between long run operations

I need a suggestion to implement the following situation:

Showing a dialog between two long run operation (SQLite DB and Network operation) that need to be performed not in UI Thread.

Which dialog is shown depends on the result of first long run operation, whereas which second long run operation is performed depends on the option selected by the user in the dialog. I have used two AsynTask (like below) to make this but program flow is very messy.

Any suggestions to make this more easily?

  1. UI thread calls AsynTask AT1
  2. AT1 doInBackGround() performs long runnung operation 1
  3. AT2 onPostExecute shows dialog
  4. UI thread handles dialog's result (using callback methods) and call AsynTask AT2
  5. AT2 doInBackGround() performs long runnung operation 2
  6. AT2 onPostExecute changes the UI.

Upvotes: 1

Views: 111

Answers (1)

Rubber Duck
Rubber Duck

Reputation: 3723

You can run each of the tasks in a separate service with its own AsyncTask and have them send their results to a Handler on the UI thread.

The handler should include the logic of deciding what to do with the input.

The communication should go through the bundle via message or a new Parcellable of your creation.

If these operation are long you should consider the user will dismiss the dialog and notify him globally [from Application or notification bar]

Upvotes: 1

Related Questions