如何关闭Android应用程序? [英] How to close Android application?
本文介绍了如何关闭Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要关闭我的应用程序,因此它不再在后台运行。
I want to close my application, so that it no longer runs in the background.
如何做到这一点?是Android平台这一好的做法呢?
How to do that? Is this good practice on Android platform?
如果我靠返回按钮,关闭应用程序,但它停留在背景。甚至有应用程序称为TaskKiller只是为了杀死在后台的应用程序。
If I rely on the "back" button, it closes the app, but it stays in background. There is even application called "TaskKiller" just to kill those apps in the background.
推荐答案
刚才回答我的问题,经过这么多的时间(因为CommonsWare评论上最流行的回答能说明问题,我们不应该这样做):
Just to answer my own question now after so much time (since CommonsWare commented on the most popular answer telling we should NOT do this):
当我想退出程序:
- 在我开始了我的第一个活动(无论是闪屏,或任何活动是目前在活动栈底)与
FLAG_ACTIVITY_CLEAR_TOP
(将退出所有其他活动正式开始之后,这意味着 - 所有的人)。只要有在活动栈本次活动(未完成它由于某种原因提前)。 - 我称之为
完成()
这个活动
- I start my first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with
FLAG_ACTIVITY_CLEAR_TOP
(which will quit all the other activities started after it, which means - all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance). - I call
finish()
on this activity
这是它的工作原理很适合我。
This is it, works quite well for me.
这篇关于如何关闭Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文