Fix Android's SDLActivity for devices that may send more than one surfaceChanged
event in a row (ie, the Kindle Fire)
--- a/android-project/src/org/libsdl/app/SDLActivity.java Fri Jun 22 23:31:22 2012 -0400
+++ b/android-project/src/org/libsdl/app/SDLActivity.java Sun Jun 24 21:10:17 2012 -0300
@@ -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 @@
// 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 @@
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 @@
// 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);
}