1

When my app is in landscape I need an extra fragment to show.

When the app changes back to portrait, the fragment does not go away and re-creates itself. Why?

Here is the sequence of FragmentActivity lifecycle methods that are the Launcher point for the app.

FragmentActivity onPause
FragmentActivity onDestroy
EditFragment onDestroy
EditFragment onCreate
FragmentActivity onCreate
FragmentActivity onResume

To initially add the fragment I use the following code in onCreate of FragmentActivity

@Override
protected void onCreate(Bundle s) {
if(Util.isLandscape(Main.this) && mEditFragment == null) {
    mEditFragment = new EditFragment();
    mFragTrans = getSupportFragmentManager().beginTransaction();
    mFragTrans.replace(R.id.main_edit_frag, mEditFragment);
    mFragTrans.addToBackStack(null);
    mFragTrans.commit();
}

And the code used in onPause of the FragmentActivity:

@Override
protected void onPause() {
    super.onPause();
    if(mEditFragment !=null) {
        mFragTrans = getSupportFragmentManager().beginTransaction();
        mFragTrans.remove( mEditFragment);
        mFragTrans.commit();
    }
hunterp
  • 15,716
  • 18
  • 63
  • 115

0 Answers0