Should we start async task from within onHandleIntent() method of IntentService? I read that onHandleIntent() runs in worker thread so will it be safe to start asyncTask from there??
Should we start async task from within onHandleIntent() method of IntentService ? I read
Share
IntentServices already are background-processes; there’s no need to start an AsyncTask from there.Also, starting anit’s a helper class that helps you multithread. Just make sure you don’t manipulateAsyncTaskis ‘safe’ from anywhere;Views in thedoInBackground()-method of your AsyncTask if you use it in your Activity.If you need to spawn multiple threads inside your IntentService, just use:
See an example at How to run a Runnable thread in Android?
If you need to call some kind of callback, use Handler. For an example, see http://www.vogella.com/articles/AndroidPerformance/article.html#handler