上面的问题基本上解释了我的问题。Advanced Task Killer 如何杀死应用程序?
我已经尝试过这个问题的第二个答案中提到的方法。哪个正在使用ActivityManager.killBackgroundProcesses.
for(RunningAppProcessInfo runningProcess : runningProcesses){
for(ApplicationInfo nonCompliantApp : nonCompliantApps){
if(runningProcess.pkgList != null) for(String runningAppPackageName : runningProcess.pkgList){
// if(runningProcess.processName.startsWith("gameapps.avatar.")){
//// FileManager.writeToLogFile(SystemApplicationManager.class, "run", LogMessageType.DEBUG, "Game Apps: " + runningProcess.processName + " pkg: " + runningProcess.pkgList.length + " - " + runningProcess.pkgList[0]);
// }
if(runningAppPackageName.equals(nonCompliantApp.packageName)){
ActivityManager amgr = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
ShellCommandManager.executeShellCommand("kill " + runningProcess.pid);
amgr.killBackgroundProcesses(nonCompliantApp.packageName);
FileManager.writeToLogFile(SystemApplicationManager.class, "run", LogMessageType.DEBUG, "Process found and killed: " + nonCompliantApp.packageName);
}
if(!keepRunning)break;
}
}
问题是,执行上述代码后,我在 settings -> apps -> running 下查看,却发现同一个应用程序仍在运行。我正在测试的设备是运行 Android ICS 的 HTC One X。
我究竟做错了什么 ?一些帮助或澄清将不胜感激。