0

I am trying to use BottomNavigatioView in my MainActivity and when on clicking a tab in the bottom navigation, the new fragment replaces the previous one, which takes the previous one to the onDestroyView state.

How can we make all the fragments in the onResume state, regardless of whether they are or not visible on the FrameLayout.

1 Answers1

0

You can save the state of fragment and can restore it on onCreateView()

Bundle savedState;

public onCreateView(...){
 ..........
     if(savedState != null){
          String hello = savedState.getString("hello");
     }
 ..........
}
@Override
public void onDestroyView(){
     super.onDestroyView();
     savedState.putString("hello", "Say hello");
}
Muhammad Aqeel
  • 81
  • 1
  • 11