src/core/android/SDL_android.c
changeset 8039 3b0346b37e0f
parent 8029 cf81e6709b3d
child 8047 a5270cef21a7
     1.1 --- a/src/core/android/SDL_android.c	Thu Nov 28 02:31:32 2013 -0800
     1.2 +++ b/src/core/android/SDL_android.c	Fri Nov 29 10:06:08 2013 -0300
     1.3 @@ -300,16 +300,17 @@
     1.4  void Java_org_libsdl_app_SDLActivity_nativePause(
     1.5                                      JNIEnv* env, jclass cls)
     1.6  {
     1.7 +    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
     1.8      if (Android_Window) {
     1.9 -        /* Signal the pause semaphore so the event loop knows to pause and (optionally) block itself */
    1.10 -        if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
    1.11          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
    1.12          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    1.13 +        SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
    1.14 +        SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    1.15 +    
    1.16 +        /* *After* sending the relevant events, signal the pause semaphore 
    1.17 +         * so the event loop knows to pause and (optionally) block itself */
    1.18 +        if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
    1.19      }
    1.20 -
    1.21 -    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
    1.22 -    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
    1.23 -    SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    1.24  }
    1.25  
    1.26  /* Resume */
    1.27 @@ -317,8 +318,6 @@
    1.28                                      JNIEnv* env, jclass cls)
    1.29  {
    1.30      __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
    1.31 -    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
    1.32 -    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
    1.33  
    1.34      if (Android_Window) {
    1.35          /* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
    1.36 @@ -326,6 +325,9 @@
    1.37           * and this function will be called from the Java thread instead.
    1.38           */
    1.39          if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
    1.40 +        
    1.41 +        SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
    1.42 +        SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
    1.43          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
    1.44          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    1.45      }