Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

android - Nested Fragment Back Press Child Inside Parent is Causing a Problem

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...