Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle single progressdialog with parallel multiple asynctask

In my Project I want to parallelly load the data from 3 different url's(webservice) while loading the page.

for this I use 3 different asynctask to load data.

I want to show the progress dialog message as "loading" when first asynctask is started and close dialog after last asynctask is completed(until complete 3 tasks show progress dialog).

Please tell me the way to handle this situation.

like image 277
Krishna Prasad Avatar asked Sep 02 '26 10:09

Krishna Prasad


1 Answers

There are different ways to handle this situation.

  1. You can use a counter variable initialized with the number of tasks, and this counter gets decremented when an AsyncTask is complete. When the counter is 0, the ProgressDialog is dismissed. You can do this decrement and checking for progress dialog dismissal in each of the AysncTask's onPostExecute.

  2. You may not need the 3 different AsyncTasks. You can use a single AsyncTask with a CountDownLatch for Thread synchronization.

like image 120
Rajesh Avatar answered Sep 04 '26 01:09

Rajesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!