想要完全关闭应用程序 [英] want to close application completely
问题描述
我想关闭我的整个应用程序.我已经试过 finishActivity()
了,但是没有用.我想在 back
press事件上完全关闭我的应用程序.我该怎么办?
i want to close my whole application. i have tried out finishActivity()
on back press but it doesn't work. I want to close my application on back
press event completely. How could i do it?
public void onImageViewClicked(View view){
switch(view.getId()){
case R.id.viewStk:
intent = new Intent(MainActivity.this,ViewStkActivity.class);
startActivityForResult(intent, 12);
break;
case R.id.about:
Intent aboutIntent = new Intent(MainActivity.this,AboutActivity.class);
startActivity(aboutIntent);
break;
}
}
推荐答案
我使用:
@Override
public void onDestroy()
{
super.onDestroy();
// Force the process to be killed on finish(), not kept around
System.runFinalizersOnExit(true);
System.exit(0);
}
使用 this.finish()
(这是该活动的替代方法)
(This is an overridden method of the activity)
人们会抱怨并告诉您它中断了Android应用程序的生命周期,但是在开发过程中在我的应用程序上使用退出"按钮可立即提高我的生产力.
People will complain and tell you it breaks the Android app lifecycle, but having an "exit" button on my app during development was an immediate boost of my productivity.
修改
显然,API的最新版本指出 runFinalizersOnExit
函数已被弃用且不安全.我在Gingerbread,ICS或JB上都没有问题.但是出于全面披露的目的,我会指出这一点.
Apparently, the latest version of the API notes that the runFinalizersOnExit
function is deprecated and unsafe. I've had no issue with it on Gingerbread, ICS, or JB. But in interest of full disclosure, I'll point this out.
这篇关于想要完全关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!