Nested Fragment Back Press Child Inside Parent is Causing a Problem
Asked Answered
L

1

1

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

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 demo link is here

image

Licketysplit answered 23/7, 2020 at 11:1 Comment(0)
A
0

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 takes care of childFragmentManager and back stack management. You can check out examples here if you wish.

Amandy answered 7/8, 2020 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.