0

I use the following snippet to kill tasks , it works perfectly fine but it doesn't kill my own app. How do i make it kill my app as well?

// kill tasks
    List<String> reservedPackages = new ArrayList<String>();
    reservedPackages.add("system");
    reservedPackages.add("com.android.launcher2");
    reservedPackages.add("com.android.inputmethod.latin");
    reservedPackages.add("com.android.phone");
    reservedPackages.add("com.android.wallpaper");
    reservedPackages.add("com.google.process.gapps");
    reservedPackages.add("android.process.acore");
    reservedPackages.add("android.process.media");
    ActivityManager am = (ActivityManager) context
            .getSystemService(Activity.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> listeProcessus = am
            .getRunningAppProcesses();
    for (RunningAppProcessInfo processus : listeProcessus) {
        String packageName = processus.processName.split(":")[0];
        if (!context.getPackageName().equals(packageName)
                && !reservedPackages.contains(packageName)) {
            am.restartPackage(packageName);
        }
    }
Cassie
  • 223
  • 2
  • 12
  • Did you go through this SO question http://stackoverflow.com/questions/3105673/how-to-kill-an-application-with-all-its-activities – Narasimha Jul 09 '16 at 14:34

2 Answers2

0

Google has recently removed the GET_TASKS permission and developers can't make changes to running tasks . The only remained way is to have a root access and close the running tasks that is not possible for All Android Users

0

As of api 21 (android lolipop) it has been removed by Google