Windows Phone Phone Calls

It will come as no surprise to you that your Windows Phone programs are interrupted when the phone rings. However, if you are running an XNA game at the time it will not actually stop. This will probably annoy your game player though, as once they come back from explaining that they don’t want any double glazing just right now they will probably find that all their lives have been lost and the game is over.
To get around this you should make your XNA game drop into pause mode when a call comes in. You can get notification of things like phone calls by binding to the Activated and Deactivated events.
this.Activated +=
new EventHandler<EventArgs>(Game1_Activated);
this.Deactivated +=
new EventHandler<EventArgs>(Game1_Deactivated);
You can get Visual Studio 2010 to do all the hard work here, just type “this.Activated +=” and then press Tab in response to the magic that happens next. Then put code into the methods that are generated and away you go.
Note: This is not what happens if the player presses Windows or Back. In those cases your game program is stopped. But that is a subject for another post I think.


Reader Comments (3)
I'm not all that concerned, since my deactivated/activated handling assumes the worst case anyway, but I can imagine my save/load state code messing something up if execution never stopped.
The other note-- is there any particular reason you're adding handler delegates instead of just overriding Game.OnActivated() and Game.OnDeactivated() with a call to the base versions afterward? That's the way I went with it, since that's how it's outlined in the XNA 4 docs.
It's worth noting that if you're also doing stuff in OnExiting(), the execution order is a little strange, at least in the emulator. I mention the details in my recent posting on the subject ( http://wp.me/pKKx6-39 ) if you're interested. I can't tell if this is the way it's supposed to work, or just a quirk of the SDK at present.
Done a sample showing tombstoning working in XNA using the gamestatemanagement sample from the CC site.
Here: http://xna-uk.net/blogs/darkgenesis/archive/2010/08/13/is-my-xna-game-dead-yet.aspx
Also, as a small point, you don't need to bind to those events, they are exposed as virtual functions in the main XNA game class, just need to overload them in you're game to handle them.
I'm binding to the events because of the way that I'm explaining it somewhere else.