我想要在Android中退出应用程序。 只需放一个“退出”按钮,杀死我的应用程序。
我知道我不应该这样做。 我知道这不是操作系统的哲学。
如果你知道如何做,请分享。
在应用程序中,我有很多打开的活动,所以“完成()”不会完成这项工作。
预先感谢您提供的信息。 Danail
I want to quit application in Android. Just put a "quit" button, which kills my app.
I know I shouldn't do this. I know that this is not the philosophy of the OS.
If you know how it can be done, pls share.
In the app, I have many opened activities, so "finish()" will not do the job.
Thank you for your information in advance. Danail
最满意答案
方式一
android.os.Process.killProcess(android.os.Process.myPid())方式二
System.exit(0);Your answer helped me, Pentium10, but I needed to do one more thing :
I had to clear(close) all my previous activities with
Intent i = new Intent();
i.setClass(this, FirstActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
This means: every activity, started after FirstActivity, is closed. (In other words, this cleans the activity stack above FirstActivity). Then all I have to do is finish my FirstActivity.
更多推荐
发布评论