清除了Android栈回 [英] Clearing the Android back stack

查看:143
本文介绍了清除了Android栈回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做类似这个问题的东西。

I'm trying to do something similar to this question.

我有一个主要的应用程序A,和子应用B和C B是一个可搜索的字典,C是一个定义,所以如果你搜索了很多的话,就可以结束与堆栈看上去就像一个> B> C> B> B> C> B> C> C>ç...等

I've got a main app A, and sub-apps B and C. B is a searchable dictionary, and C is a definition, so if you search for many words, you can end up with the stack looking like A > B > C > B > B > C > B > C > C > C... etc

每当我回去,我想回到原来的B,所以我要回栈基本上留在A> B的所有时间。

Whenever I go back, I'd like to go back to the original B, so I want the back stack to basically stay at A > B all the time.

目前我已经得到它设置使用意图,所以当后退按钮是从C pssed $ P $,它去到B的新实例,但是这显然不是我想要的。

I've currently got it set up using an Intent so when the back button is pressed from C, it goes to a new instance of B, but that's obviously not what I want.

想法?

推荐答案

不应该回击从C带你去正本提单?因此,堆栈应该是这样的:

Shouldn't hitting BACK from C take you to the original B? So the stack should look like:

A>
  B>
    C<
  B>
    C>
      C<
    C<
  B<
A

与>去到下一个活动,和&lt;作为后退按钮?

with > going to the next activity, and < being the back button?

您可以覆盖onBack pressed所有的活动,所以对于C它加载一个新的B,B就加载新的A,和A你会做 moveTaskToBack(真); ,但这是一个较小的解决方案,更是一个黑客,使其正常工作。

You could override onBackPressed for all the activities, so for C it loads a new B, B it loads a new A, and A you would do moveTaskToBack(true);, but that's less of a solution and more of a hack to make it work.

尝试使用onResume让B出现像它会在默认情况下。设置任何相关的变量,他们是在一个新的活动内容。如果你只想要这个,当你从C来,有在加载C,它被设置为true类布尔值,并检查在onResume或onRestart。如果这是真的,一切都设置为默认值/空白,且布尔设置为false。如果没有,加载它究竟是怎么回事(这是如果他们打回家,回来到应用程序,基本上)。我不是在我的办公桌,但我想你会想:

Try to use onResume so that B comes up like it would on default. Set any pertinent variables to what they are in a new activity. If you only want this when you're coming from C, have a class boolean that is set to true when C is loaded, and check it in onResume or onRestart. If it's true, set everything to default/blank, and set the boolean to false. If not, load it how it was (this is if they hit home and come back to the app, basically). I'm not at my work desk, but I think you'll want:

@Override
    public void onResume() {
        super.onResume();
        if(fromC == true){
        //Set all variables to load default dictionary
        fromC = false;
        }
    }
}

这应该使正本提单的行为像一个新型B。

This should make the original B act like a new B.

或替代,你可以做最简单的方式,当你打电话的意图加载新型B是这样的:

Or instead, you could do it the easy way, and when you call the intent to load a new B like this:

startActivity(getIntent());
finish();

这会让有只有一个B.使当你回到一点点不同,需要类变量,或者说,我想到的其他一些棘手的伎俩将其加载为空白。这有点像你想要做什么:小样本的.zip文件

That'll make there only be one B. Making it load as a blank when you go back is a little bit different and requires class variables, or some other tricky trick that I am thinking of. This is something like what you'll want to do: .zip of small sample

如果你能得到你的code改造,以类似的东西差不多(这里可以用相应的变量设置的事情工作的权利,如果让任何意义)。

If you can get your code reworked to something like that almost (where you can use the appropriate variables to set up things to work right if that makes any sense).

这篇关于清除了Android栈回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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