Try to work around Android's handling of static variables in terminated apps Android, we want to love you, but you don't make it easy for us...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index 3ce26ad..49a1d38 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -28,7 +28,7 @@ public class SDLActivity extends Activity {
private static final String TAG = "SDL";
// Keep track of the paused state
- public static boolean mIsPaused = false, mIsSurfaceReady = false, mHasFocus = true;
+ public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
public static boolean mExitCalledFromJava;
// Main components
@@ -53,22 +53,37 @@ public class SDLActivity extends Activity {
//System.loadLibrary("SDL2_ttf");
System.loadLibrary("main");
}
+
+
+ public static void initialize() {
+ // The static nature of the singleton and Android quirkyness force us to initialize everything here
+ // Otherwise, when exiting the app and returning to it, these variables *keep* their pre exit values
+ mSingleton = null;
+ mSurface = null;
+ mTextEdit = null;
+ mLayout = null;
+ mJoystickHandler = null;
+ mSDLThread = null;
+ mAudioTrack = null;
+ mExitCalledFromJava = false;
+ mIsPaused = false;
+ mIsSurfaceReady = false;
+ mHasFocus = true;
+ }
// Setup
@Override
protected void onCreate(Bundle savedInstanceState) {
- //Log.v("SDL", "onCreate()");
+ Log.v("SDL", "onCreate():" + mSingleton);
super.onCreate(savedInstanceState);
+ SDLActivity.initialize();
// So we can call stuff from static callbacks
mSingleton = this;
// Set up the surface
mSurface = new SDLSurface(getApplication());
- // Make sure this variable is initialized here!
- mExitCalledFromJava = false;
-
if(Build.VERSION.SDK_INT >= 12) {
mJoystickHandler = new SDLJoystickHandler_API12();
}
@@ -118,7 +133,6 @@ public class SDLActivity extends Activity {
@Override
protected void onDestroy() {
- super.onDestroy();
Log.v("SDL", "onDestroy()");
// Send a quit message to the application
SDLActivity.mExitCalledFromJava = true;
@@ -135,6 +149,10 @@ public class SDLActivity extends Activity {
//Log.v("SDL", "Finished waiting for SDL thread");
}
+
+ super.onDestroy();
+ // Reset everything in case the user re opens the app
+ SDLActivity.initialize();
}
@Override