Search code examples
androidandroid-activitylauncherandroid-applicationinfo

Kill all recent applications in android


When i press home key for long time in my android device.I get list of all recent applications. Now i want to kill all my recent applications pro grammatically from within my application. I am able to get list of all recent applications but not able to kill all apps.

I want to achieve it with android version 4.x

Can anyone guide me ?


Solution

  • First get a list of RunningTaskInfo records using the following:

     [public List<ActivityManager.RunningTaskInfo> getRunningTasks (int maxNum)][1]
    

    Reference

    After that, you can use the process-ids in that list to terminate the relevant processes using either

    activityManager.killBackgroundProcess(pid);
                        or
    android.os.Process.killProcess(pid);
    

    depending upon whether you can kill that process. Way to kill these is detailed here.