Skip to content

Commit

Permalink
Try to work around Android's handling of static variables in terminat…
Browse files Browse the repository at this point in the history
…ed apps

Android, we want to love you, but you don't make it easy for us...
  • Loading branch information
gabomdq committed Feb 12, 2014
1 parent 076a14b commit cf119f7
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -118,7 +133,6 @@ public void onLowMemory() {

@Override
protected void onDestroy() {
super.onDestroy();
Log.v("SDL", "onDestroy()");
// Send a quit message to the application
SDLActivity.mExitCalledFromJava = true;
Expand All @@ -135,6 +149,10 @@ protected void onDestroy() {

//Log.v("SDL", "Finished waiting for SDL thread");
}

super.onDestroy();
// Reset everything in case the user re opens the app
SDLActivity.initialize();
}

@Override
Expand Down

0 comments on commit cf119f7

Please sign in to comment.