Fix Android's SDLActivity for devices that may send more than one surfaceChanged
authorGabriel Jacobo
Sun, 24 Jun 2012 21:10:17 -0300
changeset 63442ff08dd2e5e4
parent 6343 e94f912d20b9
child 6345 b4bbb23d1b4b
Fix Android's SDLActivity for devices that may send more than one surfaceChanged
event in a row (ie, the Kindle Fire)
android-project/src/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Fri Jun 22 23:31:22 2012 -0400
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Sun Jun 24 21:10:17 2012 -0300
     1.3 @@ -26,6 +26,9 @@
     1.4  */
     1.5  public class SDLActivity extends Activity {
     1.6  
     1.7 +    // Keep track of the paused state
     1.8 +    public static boolean mIsPaused;
     1.9 +
    1.10      // Main components
    1.11      private static SDLActivity mSingleton;
    1.12      private static SDLSurface mSurface;
    1.13 @@ -61,6 +64,9 @@
    1.14          // So we can call stuff from static callbacks
    1.15          mSingleton = this;
    1.16  
    1.17 +        // Keep track of the paused state
    1.18 +        mIsPaused = false;
    1.19 +
    1.20          // Set up the surface
    1.21          mSurface = new SDLSurface(getApplication());
    1.22          setContentView(mSurface);
    1.23 @@ -160,7 +166,14 @@
    1.24              mSDLThread.start();
    1.25          }
    1.26          else {
    1.27 -            SDLActivity.nativeResume();
    1.28 +            /*
    1.29 +             * Some Android variants may send multiple surfaceChanged events, so we don't need to resume every time
    1.30 +             * every time we get one of those events, only if it comes after surfaceDestroyed
    1.31 +             */
    1.32 +            if (mIsPaused) {
    1.33 +                SDLActivity.nativeResume();
    1.34 +                SDLActivity.mIsPaused = false;
    1.35 +            }
    1.36          }
    1.37      }
    1.38  
    1.39 @@ -435,7 +448,10 @@
    1.40      // Called when we lose the surface
    1.41      public void surfaceDestroyed(SurfaceHolder holder) {
    1.42          Log.v("SDL", "surfaceDestroyed()");
    1.43 -        SDLActivity.nativePause();
    1.44 +        if (!SDLActivity.mIsPaused) {
    1.45 +            SDLActivity.mIsPaused = true;
    1.46 +            SDLActivity.nativePause();
    1.47 +        }
    1.48          enableSensor(Sensor.TYPE_ACCELEROMETER, false);
    1.49      }
    1.50