Thanks for your snippet.
I’m using it in my project but it doesn’t cover all possible cases.
For example on some devices (Motorola Xoom [4.0.4] and HTC One [4.2.2] in my case) when clock alarm is opened above our main activity OS sends callbacks in the following order:
and we lose resumeGame() call. As the result applicationWillEnterForeground event isn’t worked and game is frozen.
Note that on some devices onWindowFocusChanged is called only when you select “shooze” on alarm.
I’ve tried use solution as described there (it’s very close to yours) some time ago but it doesn’t solve black screen problem. Still I’ve used it for sound.