Question

I have a lot of async tasks in my activity, and I need to override AsyncTask for every call to do it async.

Can I replace all the AsyncTasks with BoundService + AIDL or I need to do it only with AsyncTask?

Was it helpful?

Solution

Service run in background but still run in main thread (AKA. UI thread), you will get ANR exception. according to API here:

Most confusion about the Service class actually revolves around what it is not:

  • A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
  • A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

You can use service, but you still need implement your thread logic in either service or activity,if you want something run in a separate thread.

OTHER TIPS

Service is a daemon, AsynkTask is background thread

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top