Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fix Android's SDLActivity for devices that may send more than one sur…
Browse files Browse the repository at this point in the history
…faceChanged

event in a row (ie, the Kindle Fire)
  • Loading branch information
gabomdq committed Jun 25, 2012
1 parent fb0995b commit 35efa9d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 35efa9d

Please sign in to comment.