This project is read-only.

Pause and Resume Game

Topics: Windows Phone 8
Sep 3, 2013 at 10:26 AM
Edited Sep 3, 2013 at 10:40 AM

I am trying to make a game, I have a problem with Pause and resume my game.
I used newest Github source available.
I tested your TestProject in Windows phone to learn samples. But when I pressed "Home" to hide App and display Home screen, then I touch long press Back to chose recent App, resume it to work, but all sprite, label, menu item, and other items was disappear and black screen was displayed.

Can you tell me about this problem and solution for it?
Thanks so much!

Sep 4, 2013 at 12:12 AM
I'll check it out to see what's the problem.
Sep 4, 2013 at 12:13 AM
I tried it on the WP7 emulator and it worked. Are you on Windows Phone 8?
Sep 4, 2013 at 3:13 AM
Edited Sep 4, 2013 at 3:49 AM
I tried on WP7 with Angry Ninjas Sample, it worked with no problem. But on Lumia 520 WP8, I tested this TestProject from Github Source, it worked fluently, but Pause/Resume is a problem. Please check it on WP8. I also tried a new project and it was same!

P/s: I 've just debugged.

Angry Ninjas :
Press Home -> Call ApplicationDidEnterBackground() -> Call Pause()
Long Press Back -> Call ApplicationWillEnterForeground() -> Call Resume()
WP8 Test Project (Sample):
Press Home -> Call ApplicationDidEnterBackground() -> Call Pause()
Long Press Back -> Not Call ApplicationWillEnterForeground() ->Not Call Resume()
Sep 4, 2013 at 5:56 PM
ah ha. That looks like a MonoGame issue.
Sep 5, 2013 at 5:39 AM
Edited Sep 5, 2013 at 5:44 AM
No, I think it is not a MonoGame issue, because I've tested the lastest MonoGame source
MonoGame. It work perfectly with Pause and Resume game!

Please consider about this issue ..
Sep 5, 2013 at 5:46 AM
Edited Sep 5, 2013 at 5:47 AM
if ApplicationWillEnterForeground is not called, then it is MonoGame. We simply hookup the events on the game object and wait for the callback. it would see that the event in MonoGame for WP8 is not firing properly or reliably. That's not surprising to me since the event model for the game lifecycle in MonoGame is the one place where it suffers most notably.

Evidence of this is in CCApplication:
        game.Activated += GameActivated;
        game.Deactivated += GameDeactivated;
        game.Exiting += GameExiting;

    private void GameActivated(object sender, EventArgs e)
        // Clear out the prior gamepad state because we don't want it anymore.

    private void GameDeactivated(object sender, EventArgs e)
The other possibility is an exception occurring in SaveMediaState that is halting the GameActivated call:
Sep 5, 2013 at 5:50 AM
Sure enough, upon resume, the simple audio engine is throwing an exception.
Sep 5, 2013 at 5:58 AM
Confirmed this is a monoGame bug.
Sep 5, 2013 at 6:00 AM
Totallyevil, Thanks so much!
Sep 5, 2013 at 6:02 AM
Here is the bug report for MonoGame:
Sep 5, 2013 at 6:12 AM
here's your fix:

This is a work around for the MonoGame bug.
Sep 6, 2013 at 6:12 AM
The MonoGame PR I put up does indeed fix this problem.