Replacing a Fragment with itself does not show anything

后端 未结 4 731
猫巷女王i
猫巷女王i 2021-01-12 20:19

I\'m trying to decide and show a fragment in activity\'s onResume method, but in case a previously added fragment is chosen again, then the activity goes bl

4条回答
  •  情话喂你
    2021-01-12 20:50

    You can try:

    if( !(getSupportFragmentManager().findFragmentById(R.id.myLayout) instanceof FragmentA) ) {
        FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    
        trans.replace(R.id.myLayout, fragA);
    
        trans.commit();
    }
    

    And I assume that fragA is FragmentA class object.

提交回复
热议问题