如何从一个活动完成一系列的开放式子活动? [英] How to finish series of open sub-activities from one activity?

查看:111
本文介绍了如何从一个活动完成一系列的开放式子活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个退出按钮,我的应用程序。好歹我能够跟踪活动的所有实例在我的应用程序,然后完成它们。但是,仍然有一些活动仍然活着,在某些情况下。不知道怎么办。有没有什么方法杀死的Andr​​oid特定的应用。还是有其他的方式,我可以从我的应用程序退出。

I am trying to make an exit button for my application. Anyhow I am able to track all the instance of activity in my application and then finish them all. But still some activity remain alive in some cases. Dont know how. Is there any method to kill a particular application in android. Or any other way can I exit from my application.

感谢

推荐答案

一般人不需要退出applicatios的Andr​​oid系统。有一个<一个href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238">long从CommonsWare这里解释为什么回答。然而,有几种方法可以做到。一种这样的方式是意图标志 FLAG_ACTIVITY_CLEAR_TOP 带来的针对性活动到堆栈的顶部,并关闭其他任何可能已自开放。你会使用这个,如果你有一个按钮,把用户从任何地方,他们的主菜单活动回来。该按钮将发出一个意向,启动主菜单的CLEAR_TOP标志。在主菜单可以再靠近用一个简单的完成(),你会知道,没有任何其他活动是开放的。

Generally one doesn't need to quit applicatios in Android. There's a long answer from CommonsWare here explaining why. However, there are a few ways it can be done. One such way is the intent flag FLAG_ACTIVITY_CLEAR_TOP which brings the targeted activity to the top of the stack and closes anything else that may have been open since. You'd use this if you had a button that brought the user back from wherever they were to the 'main menu' activity. That button would send an intent to start the 'main menu' with the CLEAR_TOP flag. The 'main menu' could then close with a simple finish(), and you'd know that none of the other activities were still open.

另一种方式是,如果你开始其他活动startActivityForResult,您可以使用 finishActivity(要求code)收人开始使用已要求所有活动code。

Another way is that if you started the other activities with startActivityForResult, you can use finishActivity(requestCode) to close all activities that were started with that request code.

不过,正如我上面写的,一般情况下不应需要做到这一点。

However, as I wrote above, generally you shouldn't need to do this.

这篇关于如何从一个活动完成一系列的开放式子活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆