Android: don't allow multiple instance of SDLActivity
authorSylvain Becker <sylvain.becker@gmail.com>
Mon, 07 Jan 2019 17:06:50 +0100
changeset 125110ef0e4cb7752
parent 12510 6fb31043d8a8
child 12512 afc8e5d1d992
Android: don't allow multiple instance of SDLActivity

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/56e9c709db7e

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 !
android-project/app/src/main/AndroidManifest.xml
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/app/src/main/AndroidManifest.xml	Mon Jan 07 11:35:31 2019 +0100
     1.2 +++ b/android-project/app/src/main/AndroidManifest.xml	Mon Jan 07 17:06:50 2019 +0100
     1.3 @@ -54,6 +54,8 @@
     1.4       
     1.5          <activity android:name="SDLActivity"
     1.6              android:label="@string/app_name"
     1.7 +            android:alwaysRetainTaskState="true"
     1.8 +            android:launchMode="singleInstance"
     1.9              android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    1.10              >
    1.11              <intent-filter>
     2.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jan 07 11:35:31 2019 +0100
     2.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jan 07 17:06:50 2019 +0100
     2.3 @@ -386,8 +386,6 @@
     2.4  
     2.5          if (SDLActivity.mBrokenLibraries) {
     2.6             super.onDestroy();
     2.7 -           // Reset everything in case the user re opens the app
     2.8 -           SDLActivity.initialize();
     2.9             return;
    2.10          }
    2.11  
    2.12 @@ -405,15 +403,9 @@
    2.13              } catch(Exception e) {
    2.14                  Log.v(TAG, "Problem stopping thread: " + e);
    2.15              }
    2.16 -            SDLActivity.mSDLThread = null;
    2.17 -
    2.18 -            //Log.v(TAG, "Finished waiting for SDL thread");
    2.19          }
    2.20  
    2.21          super.onDestroy();
    2.22 -
    2.23 -        // Reset everything in case the user re opens the app
    2.24 -        SDLActivity.initialize();
    2.25      }
    2.26  
    2.27      @Override
    2.28 @@ -1711,12 +1703,12 @@
    2.29             return;
    2.30          }
    2.31  
    2.32 +        /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
    2.33 +        SDLActivity.onNativeSurfaceChanged();
    2.34 +
    2.35          /* Surface is ready */
    2.36          SDLActivity.mIsSurfaceReady = true;
    2.37  
    2.38 -        /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
    2.39 -        SDLActivity.onNativeSurfaceChanged();
    2.40 -
    2.41          SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
    2.42          SDLActivity.handleNativeState();
    2.43      }