tags:

views:

720

answers:

3

Maybe you can help.

Is it possible to get list of all process which are running in the Android system, and kill some of them? I know that there are some applications (task managers), but I would like to write my own, simple application.

I would like to write simple task manager, just list of all process and button which will kill some of them.

Could you just write some Java methods which I can call in order to get list of process, and method for killing them. Or just give me some advices.

Thanks for answers.

Regards Martin

+9  A: 

Killing apps/services in Android is generally a really bad idea. Whilst it is possible to write "task killer" apps, it shouldn't be encouraged for anything outside of development/debugging purposes.

Task management is the responsibility of the Android O/S, the tasks you can see are not processes (in the sense of the processes you see in the Windows task manager for example), in fact, they only have a process when Android tells them they can have one.

Apps are regularly broken by these task management tools, as they often fail to recover from the forced termination, particularly if they were busy writing to a file or using another resource when they were killed. It also puts the handset users into a false expectation that the apps listed are actually RUNNING on their phone, which they are often not. This is explained in the ActivityManager docs:

Information you can retrieve about a particular task that is currently "running" in the system. Note that a running task does not mean the given task actual has a process it is actively running in; it simply means that the user has gone to it and never closed it, but currently the system may have killed its process and is only holding on to its last state in order to restart it when the user returns.

When you see the list of "running" apps in apps like TaskKiller or Quick System Info, many of them are not actually running, they are just in a suspended state. These apps are not consuming system resources because Android has decided to stop them until they are needed again. However, when you kill them, you don't give them time to shut down cleanly, and when you try to launch them next time you can be presented with an unfriendly force close dialog. I have seen apps break completely, with even a re-install being ineffective, because they are trying to read a corrupted file on the SD card, or they use unofficial API calls.

In short, friends don't let friends use task killers in Android.

Anyway, to answer your question, the ActivityManager is what most of these apps use to list activities that are in running/suspended state.

This is an example of one of these "task managers" in use:

http://code.google.com/p/freetaskmanager/source/browse/

seanhodges
Ok, I see. Thank you for clarification. So maybe I will try to write my simple task manager.
Martin
Fantastic explanation!
Erich Douglass
While I agree killing processes is a bad idea, I find that on my phone it can be necessary as some applications don't provide a way of closing themselves properly and my phone can become quite slow and unreactive. Using a task killer solves this problem.
stealthcopter
A: 

By the way, have anybody ever tried to write your own task manager? Can you send some code example: how to list all tasks which are running in the system, and how to close them?

Thanks for help.

Martin
A: 

Also, it seems that this ability has been removed in the Android 2.2 SDK....

Justin