mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-29 20:27:12 +01:00
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...
This commit is contained in:
parent
076a14b263
commit
cf119f786a
@ -28,7 +28,7 @@ public class SDLActivity extends Activity {
|
|||||||
private static final String TAG = "SDL";
|
private static final String TAG = "SDL";
|
||||||
|
|
||||||
// Keep track of the paused state
|
// 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;
|
public static boolean mExitCalledFromJava;
|
||||||
|
|
||||||
// Main components
|
// Main components
|
||||||
@ -54,21 +54,36 @@ public class SDLActivity extends Activity {
|
|||||||
System.loadLibrary("main");
|
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
|
// Setup
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
//Log.v("SDL", "onCreate()");
|
Log.v("SDL", "onCreate():" + mSingleton);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
SDLActivity.initialize();
|
||||||
// So we can call stuff from static callbacks
|
// So we can call stuff from static callbacks
|
||||||
mSingleton = this;
|
mSingleton = this;
|
||||||
|
|
||||||
// Set up the surface
|
// Set up the surface
|
||||||
mSurface = new SDLSurface(getApplication());
|
mSurface = new SDLSurface(getApplication());
|
||||||
|
|
||||||
// Make sure this variable is initialized here!
|
|
||||||
mExitCalledFromJava = false;
|
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= 12) {
|
if(Build.VERSION.SDK_INT >= 12) {
|
||||||
mJoystickHandler = new SDLJoystickHandler_API12();
|
mJoystickHandler = new SDLJoystickHandler_API12();
|
||||||
}
|
}
|
||||||
@ -118,7 +133,6 @@ public class SDLActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
|
||||||
Log.v("SDL", "onDestroy()");
|
Log.v("SDL", "onDestroy()");
|
||||||
// Send a quit message to the application
|
// Send a quit message to the application
|
||||||
SDLActivity.mExitCalledFromJava = true;
|
SDLActivity.mExitCalledFromJava = true;
|
||||||
@ -135,6 +149,10 @@ public class SDLActivity extends Activity {
|
|||||||
|
|
||||||
//Log.v("SDL", "Finished waiting for SDL thread");
|
//Log.v("SDL", "Finished waiting for SDL thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
// Reset everything in case the user re opens the app
|
||||||
|
SDLActivity.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user