我怎样才能杀死Android的过程? [英] How can I kill processes in Android?

查看:227
本文介绍了我怎样才能杀死Android的过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个$ C $低于C:

I have this code below:

package com.example.killall;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
//import android.widget.TextView;
import android.app.ActivityManager;

public class MainKill extends Activity {

private Button BprocessesKill ;
//private TextView processesKill;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_kill);

    final ActivityManager am=(ActivityManager)     getSystemService("SYSTEM_ACTIVITY");

    BprocessesKill=(Button) this.findViewById(R.id.BkillProcesses);
    //processesKill=(TextView) this.findViewById(R.id.killProcesses);



    BprocessesKill.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            am.killBackgroundProcesses(getPackageName());

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_kill, menu);
    return true;
}

}

我想要做的就是简单地preSS的按钮,杀死所有后台进程......这个问题我有这个code是,当我是pressing按钮,它让我看到消息:不幸的是KillAll(这是我的应用程序的名字)已经停止。我应该怎么改?

All I want to do is simply to press the button and kill all background processes.. the problem I have with this code is that when I am pressing the button it shows me the message : Unfortunately KillAll(that's my app's name) has stopped. What should I change?

推荐答案

我用这个code杀了我自己的进程(应用程序):

I use this code to kill my own process (app) :

    android.os.Process.killProcess(android.os.Process.myPid());

这篇关于我怎样才能杀死Android的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆