Reputation: 475
Is that a normal practice of using AsyncTask in Service (not IntentService). Or is it better to create background thread in another way?
Upvotes: 1
Views: 653
Reputation: 7494
No, an AsyncTask is designed to run some short lived work in a background thread away from the UI thread. It has callbacks that allows it to modify the UI thread once it is completed.
If you need a separate thread in a service, create a thread using new Thread()
Upvotes: 1
Reputation: 1006674
Is that a normal practice of using AsyncTask in Service
No. The point of AsyncTask
is to be able to do some work on the main application thread after the background work is completed. Services rarely, if ever, need to do work on the main application thread.
Or is it better to create background thread in another way?
Yes: new Thread()
would be a strong candidate as a straight-up replacement for AsyncTask
. In other cases, some form of thread pool might make sense.
Upvotes: 4