从backstack片段消失片段、backstack

2023-09-12 21:56:14 作者:习惯所有的假

为什么 FragmentTwo 从backstack在下列情况下消失:

Why does FragmentTwo disappear from the backstack in the following situation:

在我的应用程序有一个片段名为 FragmentOne 活动 FragmentOne 持有按钮。单击时,它会启动 FragmentTwo ,它被添加到片段 backstack。 FragmentTwo 有一个按钮,点击它时,增加了两个选项卡动作条链接到两个片段 FragmentThree FragmentFour FragmentThree 是可见的。 如果我现在单击后退按钮,我期望看到 FragmentTwo 。相反,我看到 FragmentOne 。哪里 FragmentTwo 去了? My app has a Fragment called FragmentOne in an Activity. FragmentOne holds a Button. When clicked, it launches FragmentTwo, which is added to the Fragment backstack. FragmentTwo has a Button, which when clicked adds two tabs to the ActionBar linked to two Fragments, FragmentThree and FragmentFour. FragmentThree is visible. If I now click the back button, I expected to see FragmentTwo. Instead, I see FragmentOne. Where did FragmentTwo go?

在我重写的onkeydown(),并开始实施自己的backstack的片段我想问问是否有一些明显的我失踪?请注意,没有配置更改测试这个时候发生了。

Before I override onKeyDown() and start implementing my own backstack for Fragments I wanted to ask if there is something obvious I am missing? Note there is no configuration change happening when testing this.

详细信息:

FragmentOne的按钮单击处理程序包含:

FragmentOne's button click handler contains:

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    FragmentTwo fragment = new FragmentTwo();
    ft.addToBackStack(null);
    ft.replace(android.R.id.content, fragment).commit();

FragmentTwo按一下按钮将在活动处理:

FragmentTwo button click is handled in the Activity:

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    FragmentFour fragmentThree = new FragmentThree();
    FragmentFive fragmentFive = new FragmentFive();

    ActionBar.Tab tab = getActionBar().newTab().setText("Frag 3").setTabListener(new CustomTabListener<FragmentThree>(fragmentThree));
    getActionBar().addTab(tab);
    tab = getActionBar().newTab().setText("Frag 4").setTabListener(new CustomTabListener<FragmentFour>(fragmentFour));
    getActionBar().addTab(tab);

,其中选项卡监听器:

where the tab listener is:

public static class CustomTabListener<T extends Fragment> implements TabListener {
    Fragment fragment;

    public CustomTabListener(Fragment fragment) {
        this.fragment = fragment;
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(android.R.id.content, fragment);
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {

    }
}

我如果添加更多的片段 FragmentThree 来backstack显示,它始终是只有片段立即 FragmentThree 已经消失。

I if add more Fragments to backstack before FragmentThree is shown, it is always and only the Fragment immediately before FragmentThree that has disappeared.

当我离开由$ P $选项卡式用户视图pssing返回键,返回 FragmentOne ,标签仍显示。我明白我需要重新设置动作条 NAVIGATION_MODE_STANDARD ,但目前还不清楚为什么 FragmentOne 正呈现>而不是 FragmentTwo