views:

37

answers:

1

So from what I've known, if I do an AsyncTask inside an Activity, the task may be killed when user quits the Activity before it is finished. One solution I've seen is using IntentService, which the system will try hard not to kill.

My problem is that IntentService only uses one background thread to run all the tasks one by one. I have several independent tasks that I wish to run concurrently, and that makes a difference in the UI (not serious, but could surprise user).

How do I accomplish this? I imagine I could have several IntentService but this seems awkward and not scalable. How do I maintain sort of a threadpool that has a good priority, so that it won't get killed to easily by the system?

If I start a (normal) Service, then launch some AsyncTasks within there, does that result in a higher priority?

Many thanks.

A: 

I'm sure its not what you would like me tell you but, you may need to reconsider your design to NOT run this many things in the background. This of course all depends on what exactly you are trying to accomplish, so please elaborate if you will on what exactly you are doing in the background.

For the second half of your question. Starting a service and launching AsyncTasks from there will not result in any higher priority. This is because AsyncTask must be started on the UI thread (same if launched from either the Activity or Service level)

If you are running multiple networking threads, PLEASE STOP its really bad practice and wastes a lot of battery power. You are better off running them one at a time.

smith324