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