From 8c1372aa278723bcc008d6b9ca59970976788040 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 4 Dec 2020 19:51:25 -0500 Subject: [PATCH] v0.9.1: (hopefully) fixed some edge case bugs with android lifecycle --- .../android/AndroidGame.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java index ef445a179..487da017a 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java @@ -28,6 +28,7 @@ import android.os.Build; import android.os.Bundle; import com.badlogic.gdx.Files; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; @@ -115,6 +116,38 @@ public class AndroidGame extends AndroidApplication { } + @Override + protected void onResume() { + //prevents weird rare cases where the app is running twice + if (instance != this){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + finishAndRemoveTask(); + } else { + finish(); + } + } + super.onResume(); + } + + @Override + protected void onDestroy() { + //LibGDX itself doesn't clear these in every case, so we do it ourselves to be sure + graphics.clearManagedCaches(); + audio.dispose(); + Gdx.app = null; + Gdx.input = null; + Gdx.audio = null; + Gdx.files = null; + Gdx.graphics = null; + Gdx.net = null; + + if (instance == this) { + instance = null; + view = null; + } + super.onDestroy(); + } + @Override public void onBackPressed() { //do nothing, game should catch all back presses