android 杀后台所有进程

//杀 后台进程
try {
    Log.i(TAG, "forceStopPackage run");
    ActivityManager m= (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    Method method = m.getClass().getMethod("forceStopPackage", String.class);
    Log.i(TAG, "forceStopPackage 0");
    method.setAccessible(true);

    List appProcesses = m.getRunningAppProcesses();
    if (appProcesses == null) {
        return;
    }
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        // The name of the process that this object is associated with.       
        Log.i(TAG, "forceStopPackage, appProcess.processName = "+appProcess.processName);      
        method.invoke(m, appProcess.processName);        
    }
} catch (Exception e) {
    Log.i(TAG, "forceStopPackage ="+e.toString());
}

你可能感兴趣的:(android 杀后台所有进程)