From 671033fdd2b8991682037e32577a9657b75e2f0d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 10 Oct 2020 19:57:58 +1000 Subject: [PATCH] Android: Fix disabling save state on exit not working --- .../github/stenzek/duckstation/EmulationActivity.java | 7 +++++-- .../com/github/stenzek/duckstation/MainActivity.java | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java index bd5b77d02..32b299b28 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java @@ -36,6 +36,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde */ private SharedPreferences mPreferences; private boolean mWasDestroyed = false; + private boolean mStopRequested = false; private boolean mWasPausedOnSurfaceLoss = false; private boolean mApplySettingsOnSurfaceRestored = false; private String mGameTitle = null; @@ -101,7 +102,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde public void onEmulationStopped() { runOnUiThread(() -> { AndroidHostInterface.getInstance().stopEmulationThread(); - if (!mWasDestroyed) + if (!mWasDestroyed && !mStopRequested) finish(); }); } @@ -162,7 +163,8 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde Log.i("EmulationActivity", "Surface destroyed"); // Save the resume state in case we never get back again... - AndroidHostInterface.getInstance().saveResumeState(true); + if (!mStopRequested) + AndroidHostInterface.getInstance().saveResumeState(true); mWasPausedOnSurfaceLoss = AndroidHostInterface.getInstance().isEmulationThreadPaused(); AndroidHostInterface.getInstance().pauseEmulationThread(true); @@ -292,6 +294,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde case 4: // Quit { + mStopRequested = true; finish(); return; } diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java index f29c22a99..789d297e9 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java @@ -54,6 +54,11 @@ public class MainActivity extends AppCompatActivity { private ListView mGameListView; private boolean mHasExternalStoragePermissions = false; + private boolean shouldResumeStateByDefault() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + return prefs.getBoolean("Main/SaveStateOnExit", true); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -71,7 +76,7 @@ public class MainActivity extends AppCompatActivity { findViewById(R.id.fab_resume).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startEmulation(null, true); + startEmulation(null, shouldResumeStateByDefault()); } }); @@ -82,7 +87,7 @@ public class MainActivity extends AppCompatActivity { mGameListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - startEmulation(mGameList.getEntry(position).getPath(), true); + startEmulation(mGameList.getEntry(position).getPath(), shouldResumeStateByDefault()); } }); mGameListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {