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.