如何使用进程ID退出选择运行的应用程序 [英] How to exit selected running applications using process id
问题描述
我用这code停止在Android手机中选择运行的应用程序:
I am using this code to stop the selected running applications in android phone:
Button view = (Button)findViewById(R.id.button1);
view.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
String appname = getIntent().getExtras().getString("appname");
String pname=appname.split("\n")[3];
int id=Integer.parseInt(pname);
finish();
android.os.Process.killProcess(id);
该ID是正确的,但这种code不工作...任何帮助? 是否有任何其他code。通过使用他们的ID来终止进程??
The Id is correct but this code is not working... any help?? Is there any other code to kill processes by using their id??
推荐答案
如果您选中的用于终止进程的Android API 它说以下内容:
if you check the Android API for Kill Process it says the following:
杀死与给定PID的进程。需要注意的是,虽然该API允许我们要求杀根据PID任何进程,内核还是会施加其上的PID你实际上能杀死标准的限制。通常,这意味着只能在运行调用者的包/应用程序,并通过该应用程序创建的任何其他进程的进程;包共享一个共同的UID也将能够杀死对方的过程。
Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.
这个答案可以解释为什么它是如此,它是如何工作的: http://stackoverflow.com/a/7560009/1306012一>
This answer explains why it is so and how it works: http://stackoverflow.com/a/7560009/1306012
这篇关于如何使用进程ID退出选择运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!