本文介绍了如何杀死Android中的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
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;
}
}
我想做的只是按下按钮并杀死所有后台进程..我对这段代码的问题是,当我按下按钮时,它会向我显示消息:不幸的是 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?
推荐答案
- 您收到的消息表明您的应用已崩溃.您需要查看其 LogCat 以找出原因.这在 Android 开发者指南中有所记录.
- 请说明您杀死所有后台进程的原因,因为我想不出任何合适的理由来执行此操作.人们坚持声称任务杀手"或应用杀手"可以提高性能,但这种态度忽略了真正的问题:编写糟糕的应用程序.只要我们继续声称任务杀手有帮助,用户就会继续使用让不必要的服务等运行的应用程序.强迫用户使用任务杀手就像处理白蚁问题一样,在您看到白蚁时一次杀死一只白蚁.真正的答案是消灭所有白蚁.
简而言之,任何向您展示如何杀死所有后台进程的人都是在伤害您,对 Android 社区也是一种伤害.
In short, anyone who shows you how to kill all background processes is doing you a disservice and the Android community a disservice.
这篇关于如何杀死Android中的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!