Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage number of threads inside Sync Task

What i am looking for is to find a way to manage a number of threads inside the Asyntask.

I need to sync my local database with server updates. This might be large data that can be retrieved using paging.

Can anybody tell me what is preferred way to manage generating threads in loop inside the asyntask so that it could display Progress Dialog until all of the thread completed.

I am little worried about the local database object & its synchronization during execution of different threads in order to download data from server & save/update into local database.

Note: I cant download all data from server in a single server call.

Thanks in advance.

like image 278
Suresh Sharma Avatar asked Nov 04 '22 00:11

Suresh Sharma


1 Answers

If it's long running operation you should use IntentService instead of AsyncTask. IntentService is UI independent so you can run it in background. To update UI you can send broadcast intent. I use IntentService for DB sync. I get data from server, while parsing I create batch updates and then update local DB with one batch update.

like image 121
Martin Vandzura Avatar answered Nov 09 '22 11:11

Martin Vandzura