diff -r 36c04a8c6545 android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Wed Jun 05 23:11:20 2013 -0700 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Thu Jun 06 15:14:56 2013 +0300 @@ -83,14 +83,33 @@ protected void onPause() { Log.v("SDL", "onPause()"); super.onPause(); - // Don't call SDLActivity.nativePause(); here, it will be called by SDLSurface::surfaceDestroyed + if (!SDLActivity.mIsPaused) { + SDLActivity.mIsPaused = true; + SDLActivity.nativePause(); + } + if (SDLActivity.mSurface.getHolder().getSurface().isValid()) { + mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false); + } } @Override protected void onResume() { Log.v("SDL", "onResume()"); super.onResume(); - // Don't call SDLActivity.nativeResume(); here, it will be called via SDLSurface::surfaceChanged->SDLActivity::startApp + SDLActivity.applyResume(); + } + + /* If the surface has been destroyed before (not always the case), we let + * surfaceChanged call us. Furthermore, some Android variants may send + * multiple surfaceChanged events, so we don't need to resume every time + * we get one of those events, only if it comes after an actual resume. + */ + public static void applyResume() { + if (SDLActivity.mIsPaused && SDLActivity.mSurface.getHolder().getSurface().isValid()) { + SDLActivity.nativeResume(); + SDLActivity.mIsPaused = false; + mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); + } } @Override @@ -232,16 +251,8 @@ if (mSDLThread == null) { mSDLThread = new Thread(new SDLMain(), "SDLThread"); mSDLThread.start(); - } - else { - /* - * 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; - } + } else { + SDLActivity.applyResume(); } } @@ -540,11 +551,6 @@ @Override public void surfaceDestroyed(SurfaceHolder holder) { Log.v("SDL", "surfaceDestroyed()"); - if (!SDLActivity.mIsPaused) { - SDLActivity.mIsPaused = true; - SDLActivity.nativePause(); - } - enableSensor(Sensor.TYPE_ACCELEROMETER, false); } // Called when the surface is resized