[Android] Fixes Bug 2041 - can't get SDL_QUIT event...
authorGabriel Jacobo <gabomdq@gmail.com>
Wed, 06 Nov 2013 11:23:24 -0300
changeset 7910261addaa47d0
parent 7909 4434ab25abf3
child 7911 a9135f92ddba
[Android] Fixes Bug 2041 - can't get SDL_QUIT event...

Thanks to Denis Bernard!

Also, changed the Android manifest so the app doesn't quit with orientation
changes, and made testgles.c exit properly on Android.
android-project/AndroidManifest.xml
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
src/video/android/SDL_androidevents.c
test/testgles.c
     1.1 --- a/android-project/AndroidManifest.xml	Wed Nov 06 09:48:45 2013 -0300
     1.2 +++ b/android-project/AndroidManifest.xml	Wed Nov 06 11:23:24 2013 -0300
     1.3 @@ -22,7 +22,9 @@
     1.4                   android:allowBackup="true"
     1.5                   android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
     1.6          <activity android:name="SDLActivity"
     1.7 -                  android:label="@string/app_name">
     1.8 +                  android:label="@string/app_name"
     1.9 +                  android:configChanges="keyboardHidden|orientation"
    1.10 +                  >
    1.11              <intent-filter>
    1.12                  <action android:name="android.intent.action.MAIN" />
    1.13                  <category android:name="android.intent.category.LAUNCHER" />
     2.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Wed Nov 06 09:48:45 2013 -0300
     2.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Wed Nov 06 11:23:24 2013 -0300
     2.3 @@ -121,13 +121,13 @@
     2.4          SDLActivity.nativeQuit();
     2.5  
     2.6          // Now wait for the SDL thread to quit
     2.7 -        if (mSDLThread != null) {
     2.8 +        if (SDLActivity.mSDLThread != null) {
     2.9              try {
    2.10 -                mSDLThread.join();
    2.11 +                SDLActivity.mSDLThread.join();
    2.12              } catch(Exception e) {
    2.13                  Log.v("SDL", "Problem stopping thread: " + e);
    2.14              }
    2.15 -            mSDLThread = null;
    2.16 +            SDLActivity.mSDLThread = null;
    2.17  
    2.18              //Log.v("SDL", "Finished waiting for SDL thread");
    2.19          }
     3.1 --- a/src/core/android/SDL_android.c	Wed Nov 06 09:48:45 2013 -0300
     3.2 +++ b/src/core/android/SDL_android.c	Wed Nov 06 11:23:24 2013 -0300
     3.3 @@ -283,9 +283,16 @@
     3.4  void Java_org_libsdl_app_SDLActivity_nativeQuit(
     3.5                                      JNIEnv* env, jclass cls)
     3.6  {
     3.7 +    /* Discard previous events. The user should have handled state storage
     3.8 +     * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
     3.9 +     * events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
    3.10 +    SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
    3.11      /* Inject a SDL_QUIT event */
    3.12      SDL_SendQuit();
    3.13      SDL_SendAppEvent(SDL_APP_TERMINATING);
    3.14 +    /* Resume the event loop so that the app can catch SDL_QUIT which
    3.15 +     * should now be the top event in the event queue. */
    3.16 +    if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
    3.17  }
    3.18  
    3.19  /* Pause */
     4.1 --- a/src/video/android/SDL_androidevents.c	Wed Nov 06 09:48:45 2013 -0300
     4.2 +++ b/src/video/android/SDL_androidevents.c	Wed Nov 06 11:23:24 2013 -0300
     4.3 @@ -82,7 +82,9 @@
     4.4              isPaused = 0;
     4.5              
     4.6              /* Restore the GL Context from here, as this operation is thread dependent */
     4.7 -            android_egl_context_restore();
     4.8 +            if (!SDL_HasEvent(SDL_QUIT)) {
     4.9 +                android_egl_context_restore();
    4.10 +            }
    4.11          }
    4.12      }
    4.13      else {
     5.1 --- a/test/testgles.c	Wed Nov 06 09:48:45 2013 -0300
     5.2 +++ b/test/testgles.c	Wed Nov 06 11:23:24 2013 -0300
     5.3 @@ -335,7 +335,9 @@
     5.4          SDL_Log("%2.2f frames per second\n",
     5.5                 ((double) frames * 1000) / (now - then));
     5.6      }
     5.7 +#if !defined(__ANDROID__)
     5.8      quit(0);
     5.9 +#endif        
    5.10      return 0;
    5.11  }
    5.12