nicolasgramlich/AndEngine — Issue #36: When I press home button, AndEngine calls onPauseGame and onResumeGame at the same time. When I resume the game, onResumeGame is not called.
Author: sjvc
Created: 2012-02-10 19:13:26+00:00
State: open

Running on Samsung Galaxy S2, with Android 2.3.6. When I press home button, game goes background, and AndEngine calls onPauseGame and immediately onResumeGame. When I resume the game, onResumeGame is not called.

The problem is in BaseGameActivity, when onWindowFocusChanged event is called, for some reason pHasWindowFocus is true, and onResumeGame is called.

I tried to debug, I added the "Debug.d" line:

@Override
public synchronized void onWindowFocusChanged(final boolean pHasWindowFocus) {
super.onWindowFocusChanged(pHasWindowFocus);

Debug.d("pHasWindowFocus:" + String.valueOf(pHasWindowFocus));

if(pHasWindowFocus && this.mGamePaused && this.mGameCreated) {
this.onResumeGame();
}
}

And this is the log I get when I press home button:

02-10 20:04:47.640: D/AndEngine(29438): DoodleJuggleActivity.onPause @(Thread: 'main')
02-10 20:04:47.680: D/AndEngine(29438): DoodleJuggleActivity.onPauseGame @(Thread: 'main')
02-10 20:04:47.725: D/AndEngine(29438): pHasWindowFocus:false
02-10 20:04:47.730: D/AndEngine(29438): pHasWindowFocus:true
02-10 20:04:47.730: D/AndEngine(29438): DoodleJuggleActivity.onResumeGame @(Thread: 'main')
02-10 20:04:47.730: D/AndEngine(29438): pHasWindowFocus:false

Seems that onWindowFocusChanged is called more than once...