在Android中退出应用程序(Quitting application in Android)

编程入门 行业动态 更新时间:2024-10-26 18:20:59
在Android中退出应用程序(Quitting application in Android)

我想要在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.

更多推荐

本文发布于:2023-08-07 00:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Android   application   Quitting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!