In an Activity, lets call it MasterActivity, I want to load the detail fragment with media playback only in landscape mode. The media automatically starts when ready.
Master-Detail Flow setup: I have two xmls, activity_master and activity_master.xml(land). The container view with id "detail_container" is only in the landscape xml. The purpose of the landscape xml with a detail container is to show master-detail both on the same screen, on width >900.
In onCreate(), this is how I'm determining the screen orientation though checking the existence of the "detail_container", like so:
if (findViewById(R.id.detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-w900dp).
// If this view is present, then the
mTwoPane = true;
}
and also in OnCreate() of the activity, I have the following code to automatically load the fragment when activity is in two pane mode (landscape on large-screen layouts)
if (mTwoPane) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.detail_container,
someFragment.newInstance(MEDIA_URI))
.commit();
}
Problem:
When I start the activity in vertical, the fragment isn't loaded (expected).
When I start the activity in landscape, the fragment is loaded (expected).
On screen rotation, fragment is destroyed (expected, playback stops and resources released only in onDestory());
The problem is when I start activity in landscape but rotate it to vertical, the fragment restarts, and media playback start again (unexpected).
My Goal: I want the fragment to automatically load when the device is in landscape on large screen devices, on device rotation the fragment shouldn't load again.
EDIT: In vertical mode, the fragment shouldn't load automatically, user would click in master activity, opens the detail activity, and the detail activity would host the detail fragment.
How should I go about this? Thank You in Advance
Extra Info: Test physical device is a 7' tablet running Android 5.0 API 21, the issue is also present in emulator.