父级中的嵌套片段backpress孩子有问题 [英] Nested fragment backpress child inside parent have problem

查看:81
本文介绍了父级中的嵌套片段backpress孩子有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有嵌套片段,片段内有片段.使用 NavigationBottomView .当我从父片段压缩到子片段时,一切正常.

I have nested fragment, fragment inside fragment. Using NavigationBottomView. Everything goes right when I backpress from parent to child fragment.

但是,现在,如果我在子片段中,突然我的手机屏幕关闭了,并且如果我再次打开屏幕并从我离开的地方进行反向按下,那没有用,我认为这是我忘记了或清除了我的反向堆栈.不知道为什么.我在下面的github链接上做了一个演示

But now, if I am inside child fragment and suddenly my phone screen goes off, and if I Open the screen again and backpress from where I left, it's not going I think it is forgot or clear my backstack. Don't know why. I have made a demo on github link below

  MessageListningFragment messageListningFragment = new MessageListningFragment();
    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    transaction.addToBackStack( null );
    transaction.replace( R.id.dynamic_container, messageListningFragment ).commitAllowingStateLoss();

github演示链接在这里

推荐答案

您应该使用带有NavHost片段的ViewPager/ViewPager2或带有

You should either use a ViewPager/ViewPager2 with NavHost fragments or implement BottomNavigationView with extension functions Google provided, which basically tags fragments and add them with NavHostFragment.create().

NavHostFragment负责childFragmentManager和后向堆栈管理.您可以在此处查阅示例.

NavHostFragment takes care of childFragmentManager and back stack management. You can check out examples here if you wish.

这篇关于父级中的嵌套片段backpress孩子有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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