From da837c4d2e68784b9e65e3cbf526aa4aef596ee0 Mon Sep 17 00:00:00 2001 From: staphen Date: Wed, 1 Dec 2021 22:22:26 -0500 Subject: [PATCH] [Android] Clear memory on exit with System.exit(0) --- .../devilutionx/DevilutionXSDLActivity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/android-project/app/src/main/java/org/diasurgical/devilutionx/DevilutionXSDLActivity.java b/android-project/app/src/main/java/org/diasurgical/devilutionx/DevilutionXSDLActivity.java index 8e88f1434..5c5fd5068 100644 --- a/android-project/app/src/main/java/org/diasurgical/devilutionx/DevilutionXSDLActivity.java +++ b/android-project/app/src/main/java/org/diasurgical/devilutionx/DevilutionXSDLActivity.java @@ -26,6 +26,7 @@ import java.util.Objects; public class DevilutionXSDLActivity extends SDLActivity { private String externalDir; + private boolean noExit; protected void onCreate(Bundle savedInstanceState) { // windowSoftInputMode=adjustPan stopped working @@ -49,10 +50,23 @@ public class DevilutionXSDLActivity extends SDLActivity { if (missingGameData()) { Intent intent = new Intent(this, DataActivity.class); startActivity(intent); + noExit = true; this.finish(); } } + /** + * When the user exits the game, use System.exit(0) + * to clear memory and prevent errors on restart + */ + protected void onDestroy() { + super.onDestroy(); + + if (!noExit) { + System.exit(0); + } + } + private void trackVisibleSpace() { this.getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override