Permalink
Browse files

Android: Fix crash on instant rotate

Delay the creation of the emulation fragment if: the device is a phone, if
emulation should be locked to landscape, and the current orientation is
portrait.
  • Loading branch information...
zackhow committed Nov 6, 2018
1 parent 710b893 commit 0446a58ec5db04ade03f24fdb091bc4513cf67b4
@@ -185,6 +185,10 @@ protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Find the EmulationFragment
mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
.findFragmentById(R.id.frame_emulation_fragment);
if (savedInstanceState == null)
{
// Get params we were passed
@@ -196,7 +200,9 @@ protected void onCreate(Bundle savedInstanceState)
}
else
{
activityRecreated = true;
// Could have recreated the activity(rotate) before creating the fragment. If the fragment
// doesn't exist, treat this as a new start.
activityRecreated = mEmulationFragment != null;
restoreState(savedInstanceState);
}
@@ -212,13 +218,6 @@ protected void onCreate(Bundle savedInstanceState)
int themeId;
if (mDeviceHasTouchScreen)
{
BooleanSetting lockLandscape =
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
.getSetting(SettingsFile.KEY_LOCK_LANDSCAPE);
// Force landscape if set
if (lockLandscape == null || lockLandscape.getValue())
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
themeId = R.style.DolphinEmulationBase;
// Get a handle to the Window containing the UI.
@@ -250,10 +249,20 @@ protected void onCreate(Bundle savedInstanceState)
setContentView(R.layout.activity_emulation);
// Find or create the EmulationFragment
mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
.findFragmentById(R.id.frame_emulation_fragment);
if (mEmulationFragment == null)
BooleanSetting lockLandscapeSetting =
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
.getSetting(SettingsFile.KEY_LOCK_LANDSCAPE);
boolean lockLandscape = lockLandscapeSetting == null || lockLandscapeSetting.getValue();
// Force landscape if set
if (mDeviceHasTouchScreen && lockLandscape)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
if (!(mDeviceHasTouchScreen && lockLandscape &&
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) &&
mEmulationFragment == null)
{
mEmulationFragment = EmulationFragment.newInstance(mPath);
getSupportFragmentManager().beginTransaction()

0 comments on commit 0446a58

Please sign in to comment.