android task kill

Cata picture Cata · Feb 7, 2011 · Viewed 19.4k times · Source

I want to kill all tasks that run in android like task killer... What I have done until now is:

ActivityManager manager =  (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses();

    for (int i = 0; i < activityes.size(); i++){

        Log.e("APP: "+i, activityes.get(0).processName);

        if (!activityes.get(0).processName.equals("app.android.myapp")){
            Process.killProcess(activityes.get(0).pid);
        }

    }

The problem with the code is that it returns in the activityes list only my app for 12 times. And no task is being killed...

Can somebody help me please? Thank you!

Answer

CommonsWare picture CommonsWare · Feb 7, 2011

You do not have the rights to kill other processes; hence, killProcess() does not work for your app.