如果已经在后台应用程序中打开并运行,我正在尝试关闭特定的 3 个应用程序。我试过这样
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CloseApps();
}
private void CloseApps() {
ActivityManager actvityManager = (ActivityManager)
this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo runningProInfo : procInfos) {
if (runningProInfo.processName.equals("com.aaa.aaaa")) {
actvityManager.killBackgroundProcesses(runningProInfo.processName);
}else if (runningProInfo.processName.equals("com.ccc.ccc")) {
actvityManager.killBackgroundProcesses(runningProInfo.processName);
}
else if (runningProInfo.processName.equals("com.bbb.bbb.ad")){
actvityManager.killBackgroundProcesses(runningProInfo.processName);
}
}
}
注意:我正在使用 android 7.1 版本。