Android 任务杀死
我想杀死所有在android中运行的任务,比如任务杀手...... 到目前为止我所做的是:
ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses();
for (int i = 0; i < activityes.size(); i++){
Log.e("APP: "+i, activityes.get(0).processName);
if (!activityes.get(0).processName.equals("app.android.myapp")){
Process.killProcess(activityes.get(0).pid);
}
}
代码的问题是它在活动列表中仅返回我的应用程序 12 次。 并且没有任务被杀死...
有人可以帮助我吗? 谢谢你!
I want to kill all tasks that run in android like task killer...
What I have done until now is:
ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses();
for (int i = 0; i < activityes.size(); i++){
Log.e("APP: "+i, activityes.get(0).processName);
if (!activityes.get(0).processName.equals("app.android.myapp")){
Process.killProcess(activityes.get(0).pid);
}
}
The problem with the code is that it returns in the activityes list only my app for 12 times.
And no task is being killed...
Can somebody help me please?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您无权终止其他进程;因此,
killProcess()
不适用于您的应用。You do not have the rights to kill other processes; hence,
killProcess()
does not work for your app.您在循环中使用 0(零)而不是 i。
干杯
You're using 0 (zero) instead of i inside your loop.
Cheers
您可以使用以下代码在按下后退键时终止当前进程:
You can kill the current process on back pressed using the following code:
您可以尝试此操作来终止您的任务或应用程序:
这适用于 2.2 及更高版本。
You can try this to kill your task or app:
this works for 2.2 and up.
1- 添加到清单
2 - 在您的代码中
请注意您的应用需要有权访问 adb shell(系统应用)
1- Add to manifest
2 - In your code
note that your app need to have access to adb shell (system app)