如何杀死在Android应用程序的所有活动? [英] how to kill all activities in android application?
本文介绍了如何杀死在Android应用程序的所有活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在android系统关闭应用程序总当我在对话框的否按钮点击。我已经使用了以下code。
I want to close total application in android when i click on "NO" Button in Dialog. i have used the following code.
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setTitle("GASIMIZER");
builder1.setCancelable(false)
.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent i = new Intent(Finalpage.this,NewproActivity.class);
startActivity(i);
}
})
.setNegativeButton("NO",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
quit();
}
});
AlertDialog alert1 = builder1.create();
alert1.show();
break;
}
return null;
}
public void quit() {
onDestroy();
}
请任何一个可以告诉我,我怎么能解决这个问题。
please any one tell me how can i solve this problem.
推荐答案
您可以调用您的活动完成()
方法和调用主屏幕(模拟为homeButton)编程是这样的:
you can call the finish()
method on your activity and call the homescreen (simulate the homebutton) programmatically like this:
private void endApplication() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
这篇关于如何杀死在Android应用程序的所有活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文