我正在使用以下代码来终止后台应用(计算器)。因为我在运行app时创建了一个服务。它不是杀死后台进程(计算器)
代码有什么问题我也给了许可。 "android.permission.KILL_BACKGROUND_PROCESSES"
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> packageName = am.getRunningTasks(10);
// String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();
for (RunningTaskInfo appinfo : packageName)
{
if((appinfo.topActivity.getPackageName().toString()).indexOf("calculator2")!= -1)
{
Log.i(Tag,""+ appinfo.topActivity.getPackageName());
Toast.makeText(MyService.this, ""+appinfo.topActivity.getPackageName(), Toast.LENGTH_SHORT).show();
am.killBackgroundProcesses(appinfo.topActivity.getPackageName());
}
}