Add a way to set the context when other activities are active so many SDL API functions still work.
authorSam Lantinga
Mon, 28 Aug 2017 23:04:47 -0700
changeset 11411f451a8bdb45e
parent 11410 535e96a0ee39
child 11412 b9725ff31b1a
Add a way to set the context when other activities are active so many SDL API functions still work.
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Mon Aug 28 22:44:48 2017 -0700
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Aug 28 23:04:47 2017 -0700
     1.3 @@ -56,6 +56,7 @@
     1.4      public static boolean mSeparateMouseAndTouch;
     1.5  
     1.6      // Main components
     1.7 +    protected static Context mContext;
     1.8      protected static SDLActivity mSingleton;
     1.9      protected static SDLSurface mSurface;
    1.10      protected static View mTextEdit;
    1.11 @@ -135,6 +136,7 @@
    1.12      public static void initialize() {
    1.13          // The static nature of the singleton and Android quirkyness force us to initialize everything here
    1.14          // Otherwise, when exiting the app and returning to it, these variables *keep* their pre exit values
    1.15 +        mContext = null;
    1.16          mSingleton = null;
    1.17          mSurface = null;
    1.18          mTextEdit = null;
    1.19 @@ -155,6 +157,9 @@
    1.20      }
    1.21  
    1.22      // Setup
    1.23 +    public static void setContext(Context context) {
    1.24 +        mContext = context;
    1.25 +    }
    1.26      @Override
    1.27      protected void onCreate(Bundle savedInstanceState) {
    1.28          Log.v(TAG, "Device: " + android.os.Build.DEVICE);
    1.29 @@ -165,7 +170,7 @@
    1.30          SDLActivity.initialize();
    1.31  
    1.32          // So we can call stuff from static callbacks
    1.33 -        mSingleton = this;
    1.34 +        mContext = mSingleton = this;
    1.35  
    1.36          // Load shared libraries
    1.37          String errorMsgBrokenLib = "";
    1.38 @@ -564,8 +569,9 @@
    1.39       */
    1.40      public static void setOrientation(int w, int h, boolean resizable, String hint)
    1.41      {
    1.42 -      mSingleton.setOrientationBis(w, h, resizable, hint);
    1.43 -      return;
    1.44 +        if (mSingleton != null) {
    1.45 +            mSingleton.setOrientationBis(w, h, resizable, hint);
    1.46 +        }
    1.47      }
    1.48     
    1.49      /**
    1.50 @@ -638,6 +644,9 @@
    1.51       * This method is called by SDL using JNI.
    1.52       */
    1.53      public static boolean sendMessage(int command, int param) {
    1.54 +        if (mSingleton == null) {
    1.55 +            return false;
    1.56 +        }
    1.57          return mSingleton.sendCommand(command, Integer.valueOf(param));
    1.58      }
    1.59  
    1.60 @@ -645,7 +654,7 @@
    1.61       * This method is called by SDL using JNI.
    1.62       */
    1.63      public static Context getContext() {
    1.64 -        return mSingleton;
    1.65 +        return mContext;
    1.66      }
    1.67  
    1.68      static class ShowTextInputTask implements Runnable {
    1.69 @@ -716,6 +725,9 @@
    1.70       * This method is called by SDL using JNI.
    1.71       */
    1.72      public static Surface getNativeSurface() {
    1.73 +        if (SDLActivity.mSurface == null) {
    1.74 +            return null;
    1.75 +        }
    1.76          return SDLActivity.mSurface.getNativeSurface();
    1.77      }
    1.78