2、代码:
package cn.zengfansheng.killproc;
import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* TODO 1、进程杀死自己,不能杀死别人
* @param view
*/
public void killself(View view) {
android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(0);//不推荐使用
System.out.println("杀死自己。。。");
}
/**
* TODO 2、进程杀死别人,不能杀死自己的进程
* @param view
*/
public void killother(View view) {
ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses("cn.zengfansheng.progresskill");
System.out.println("杀死别人。。。");
}
} |