0

I've a problem with killing third party apps from my application. Here's the code:

ActivityManager activityManager = (ActivityManager) getApplicationContext()
        .getSystemService(ACTIVITY_SERVICE);

List<RunningAppProcessInfo> appProcesses = activityManager
        .getRunningAppProcesses();
for (RunningAppProcessInfo appProcess : appProcesses) {

    if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
        if (appProcess.pkgList[0].equalsIgnoreCase("com.adobe.air")) {
            Log.v("ACTIVITY FOUND", "" + appProcess.pkgList[0]
                    + " - " + appProcess.pid);

            activityManager.killBackgroundProcesses("com.adobe.air");
            activityManager.restartPackage("com.adobe.air");

            android.os.Process.killProcess(appProcess.pid);


        }
    }
}
Log.v("RUN", "----------------------------------");

And in AndroidManifest I added the permissions android.permission.KILL_BACKGROUND_PROCESSES and android.permission.RESTART_PACKAGES.

In Log I can correctly read the message when the package com.adobe.air is running, but killBackgroundProcesses, restartPackage and KillProcess have no success force closing the app itself. What's wrong?

sheepez
  • 986
  • 1
  • 10
  • 26

1 Answers1

0
  1. You can use Process.killProcess(int pid) to kill processes that have the same UID with your App.
  2. You can use ActivityManager.killBackgroundProcesses(String packageName),with KILL_BACKGROUND_PROCESSES permission in your manifest(for API >= 8)
  3. or ActivityManager.restartPackage (String packageName)(for API < 8) to kill specified process,except of forground process.
pangang
  • 165
  • 1
  • 1
  • 9