Skip to content

Commit

Permalink
Android: don't allow multiple instance of SDLActivity
Browse files Browse the repository at this point in the history
Default launch mode (standard) allows multiple instances of the SDLActivity.
( https://developer.android.com/guide/topics/manifest/activity-element#lmode )

Not sure this is intended in SDL as this doesn't work. There are static
 variables in Java, in C code which make this impossible (allow one android_window) and
 also Audio print errors.

There is also some code added in onDestroy as if it would be able to
re-initialize: https://hg.libsdl.org/SDL/rev/27686adb08c3

Bug Android activity life-cycle seems to show there is not transition to get out
of onDestroy()
https://developer.android.com/reference/android/app/Activity#ActivityLifecycle

( can be tested with "adb shell am start  my.package.org/.MainActivity"
  and "adb shell am start -n  my.package.org/.MainActivity" )

Send me a message if there are real use-case for this !
  • Loading branch information
1bsyl committed Jan 7, 2019
1 parent cfe2924 commit 59df6d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 2 additions & 0 deletions android-project/app/src/main/AndroidManifest.xml
Expand Up @@ -54,6 +54,8 @@

<activity android:name="SDLActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
>
<intent-filter>
Expand Down
14 changes: 3 additions & 11 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Expand Up @@ -386,8 +386,6 @@ protected void onDestroy() {

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

Expand All @@ -405,15 +403,9 @@ protected void onDestroy() {
} catch(Exception e) {
Log.v(TAG, "Problem stopping thread: " + e);
}
SDLActivity.mSDLThread = null;

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

super.onDestroy();

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

@Override
Expand Down Expand Up @@ -1711,12 +1703,12 @@ else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || req
return;
}

/* Surface is ready */
SDLActivity.mIsSurfaceReady = true;

/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
SDLActivity.onNativeSurfaceChanged();

/* Surface is ready */
SDLActivity.mIsSurfaceReady = true;

SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
SDLActivity.handleNativeState();
}
Expand Down

0 comments on commit 59df6d6

Please sign in to comment.