Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Saying Au-Revior to Concorde | Main | Windows Phone 7 Training now Live »
Thursday
Aug192010

Windows Phone Phone Calls

Hull Universtiy Library

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)

Interesting that it doesn't tombstone the game like the other possibilities do. Is there a way to tell whether it's a call or something else?

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.
August 20, 2010 | Unregistered CommenterCorwyn Kalenda
Rob
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.
August 23, 2010 | Unregistered CommenterSimon (Darkside) Jackson
I've done some testing with a real phone and actual calls and in the situation when a call comes in the application still works. You get a Dactivated message when the call starts, and another when the call ends, but the game itself still runs. In fact you can touch the game screen and continue to play it during the phone call if you like. This is in keeping with the way that a phone will let you do things like look up contents or surf the web during a call, but it is rather confusing.

I'm binding to the events because of the way that I'm explaining it somewhere else.
August 25, 2010 | Registered CommenterRob

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.