1

The app is working fine until I rotate the screen. Then the two fragments get confused. Here is the code from the Activity:

private PopupScreen popupFragment;
private PlayerWindow playerWindowFragment;

and after onCreate:

if (savedInstanceState == null) {
        Log.v(TAG, "onCreate: SAVEDINSTANCESTATE IS NULL, NEW ACTIVITY and FRAGMENTS");
        popupFragment = new PopupScreen();
        playerWindowFragment = new PlayerWindow();
        Bundle args = new Bundle();
        args.putInt("defaultBtnImgValue", au);
        args.putInt("btnImg", au);
        popupFragment.setArguments(args);
        playerWindowFragment.setArguments(args);
        FragmentTransaction transaction =
                getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.popupfragmentframe, popupFragment, POPUPWINDOWFRAME);
        transaction.replace(R.id.playerwindowfragmentframe, playerWindowFragment, PLAYERWINDOWFRAME);
        transaction.commit();
    } else {
        popupFragment = (PopupScreen) getSupportFragmentManager().findFragmentByTag(POPUPWINDOWFRAME);
        playerWindowFragment = (PlayerWindow) getSupportFragmentManager().findFragmentByTag(PLAYERWINDOWFRAME);
    }`

Here is the xml for the activity. The fragments are in a LinearLayout:

<FrameLayout
    android:id="@+id/popupfragmentframe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</FrameLayout>
<FrameLayout
    android:id="@+id/playerwindowfragmentframe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</FrameLayout>

Here is the Log:

Caused by: java.lang.ClassCastException: au.com.packagename.PlayerWindow cannot be cast to au.com.packagename.PopupScreen

When I inflated the popupfragment as a Fragment instead of a FrameLayout in the Activity xml, it was OK.

Thanks for all help.

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
Immy
  • 631
  • 1
  • 5
  • 15
  • Possible duplicate of [Multiple calls to FragmentTransaction.replace() - only one works after orientation change](http://stackoverflow.com/questions/18708357/multiple-calls-to-fragmenttransaction-replace-only-one-works-after-orientati) – mdtuyen Jul 08 '16 at 04:54
  • It is slightly different, because he did have one fragment inflated. I still tried it though, but no success. I am trying to combine the two fragments into one, which is a bit clumsy, but as I couldn't find good documentation about it, there is no other choice. The fragments have got hardly anything to do with each other, so I didn't want it nested either. – Immy Jul 08 '16 at 06:47

0 Answers0