Fixes #2022, do not resume on Android when surfaceChanged
authorGabriel Jacobo <gabomdq@gmail.com>
Mon, 12 Aug 2013 11:13:50 -0300
changeset 7633 171a7ab71f28
parent 7632 d6a8fa507a45
child 7634 6a4fa34f3eba
Fixes #2022, do not resume on Android when surfaceChanged If the app is in landscape mode and the user presses the power button, a pause is followed immediately by a surfaceChanged event because the lock screen is shown in portrait mode. This triggers a "false" resume. So, we just pause and resume following the onWindowFocusChanged events. Also, wait for SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND before blocking the event pump.
android-project/src/org/libsdl/app/SDLActivity.java
src/video/android/SDL_androidevents.c
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 11 19:56:43 2013 -0700
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Aug 12 11:13:50 2013 -0300
@@ -695,11 +695,6 @@
             SDLActivity.mSDLThread = new Thread(new SDLMain(), "SDLThread");
             enableSensor(Sensor.TYPE_ACCELEROMETER, true);
             SDLActivity.mSDLThread.start();
-        } else {
-            // The app already exists, we resume via handleResume
-            // Multiple sequential calls to surfaceChanged are handled internally by handleResume
-
-            SDLActivity.handleResume();
         }
     }
 
--- a/src/video/android/SDL_androidevents.c	Sun Aug 11 19:56:43 2013 -0700
+++ b/src/video/android/SDL_androidevents.c	Mon Aug 12 11:13:50 2013 -0300
@@ -64,9 +64,9 @@
     else {
 #if SDL_ANDROID_BLOCK_ON_PAUSE
         if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
-            /* We've been signaled to pause, but before we block ourselves, we need to make sure that
-            SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED have reached the app */
-            if (SDL_HasEvent(SDL_WINDOWEVENT)) {
+            /* We've been signaled to pause, but before we block ourselves, 
+            we need to make sure that certain key events have reached the app */
+            if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
                 isPausing = 1;
             }
             else {