如何清洁回栈在Android API 10(安卓2.3.3) [英] How to clean back stack on Android API 10 (Android 2.3.3)

查看:106
本文介绍了如何清洁回栈在Android API 10(安卓2.3.3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么能清洁栈的所有previous活动(除了新建一个),但我想,在Android的API 10(安卓2.3.3)。

I would like to know how can I clean all previous activities of the stack (except the new one), but I want that in Android API 10 (Android 2.3.3).

指导下使用此回答的,我知道这不是直接可能的,因为专用的标志做的,因为API 11存在

Guided with this answer, I know it is not directly possible because the flag dedicated to do that exists since API 11.

不过,我想知道这是可能的,也许有一定的兼容性,或者如果有人有任何解决方案。

But I would like to know if this is possible maybe with some compatibility or if someone has any solution.

在此先感谢。

推荐答案

在办法做到这一点是要始终使用启动活动 startActivityForResult()。当你要清洁活动堆栈的情况下有当前活动的呼叫的setResult(RESULT_CANCELED),然后调用完成()。在所有的活动(除了你的主要还是根活动),有以下方法:

On way to do this is to always start your activities using startActivityForResult(). In the case where you want to clean the activity stack have the current activity call setResult(RESULT_CANCELED) and then call finish(). In all activities (except your main or "root" activity) have the following method:

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_CANCELED) {
        // Want to clear the activity stack so I should just go away now
        setResult(RESULT_CANCELED); // Propagate result to the previous activity
        finish();
}

这将完成所有活动在堆中。

This will finish all activities in the stack.

这篇关于如何清洁回栈在Android API 10(安卓2.3.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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