From 35efa9dba16b16bee22ebcc395e18f398decf144 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Sun, 24 Jun 2012 21:10:17 -0300 Subject: [PATCH] Fix Android's SDLActivity for devices that may send more than one surfaceChanged event in a row (ie, the Kindle Fire) --- .../src/org/libsdl/app/SDLActivity.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 0c7573c42..b0b472ceb 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -26,6 +26,9 @@ */ public class SDLActivity extends Activity { + // Keep track of the paused state + public static boolean mIsPaused; + // Main components private static SDLActivity mSingleton; private static SDLSurface mSurface; @@ -61,6 +64,9 @@ protected void onCreate(Bundle savedInstanceState) { // So we can call stuff from static callbacks mSingleton = this; + // Keep track of the paused state + mIsPaused = false; + // Set up the surface mSurface = new SDLSurface(getApplication()); setContentView(mSurface); @@ -160,7 +166,14 @@ public static void startApp() { mSDLThread.start(); } else { - SDLActivity.nativeResume(); + /* + * Some Android variants may send multiple surfaceChanged events, so we don't need to resume every time + * every time we get one of those events, only if it comes after surfaceDestroyed + */ + if (mIsPaused) { + SDLActivity.nativeResume(); + SDLActivity.mIsPaused = false; + } } } @@ -435,7 +448,10 @@ public void surfaceCreated(SurfaceHolder holder) { // Called when we lose the surface public void surfaceDestroyed(SurfaceHolder holder) { Log.v("SDL", "surfaceDestroyed()"); - SDLActivity.nativePause(); + if (!SDLActivity.mIsPaused) { + SDLActivity.mIsPaused = true; + SDLActivity.nativePause(); + } enableSensor(Sensor.TYPE_ACCELEROMETER, false); }