如何使用代码退出Android应用程序? [英] How to exit an android app using code?
问题描述
finish()
会这样做。但是,完成只是关闭当前运行的活动吗?我有很多活动,所以在这种情况下,我必须通过每一个活动的实例,完成它们或使每一个活动进入Singleton模式。 我也必须知道 Activity.moveTaskToBack(true)
可以让你进入主屏幕。好的,这不是关闭而是背景的过程。那么这是有效的吗?
我应该使用哪种方法来完全关闭应用程序?任何上述描述或任何其他方法/上述方法的其他用法?
请帮助。
可以调用System.exit();取消所有的功能。
submit =(Button)findViewById(R.id.submit);
submit.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0){
android.os.Process.killProcess (android.os.Process.myPid());
System.exit(1);
}
});
I am sure this question has been asked number of times because I read few. My client wants me to put a button into his app where users can click and exit. I have read this and found calling finish()
will do it. But, finish is only closing the current running activity right? I have lot of activities so in this case I have to pass each and every activity's instance and finish them or make every activity into Singleton pattern.
I also got to know Activity.moveTaskToBack(true)
can get you into the home screen. OK, this is not closing but backgrounding the process. So is this is effective?
Which method should I use to close the app COMPLETELY? Any of above described or any other method/other usage of above methods?
Please help.
You can call System.exit(); to get out of all the acivities.
submit=(Button)findViewById(R.id.submit);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
});
这篇关于如何使用代码退出Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!