Saturday, 14 December 2013

WP7 Run Under Lock Screen Mystery

My son just returned from the Varsity Ski Trip, and used Skied Demon on a Windows Phone 7.  Now I know there aren’t many people out there who actually have one of these phones, and we rewrote the software to work while making phone calls on WP8, however, it still irks me when code we wrote doesn’t work for some of our customers.

The problem goes like this:

My son starts logging in the app, and then presses the power button to lock the screen and save power.

Later, he sees something that requires a photo and presses the camera button to wake up the phone.

After he backs out of the camera, he finds that the program is no longer running.

Of course, while on holiday, he had better things to do than tell his father an app isn’t working like he thinks it should be, but now he’s back, I’ve looked into the cause (30 minutes from bug report to investigation.  That’s how we like to treat all bug reports, so if one of our apps crashes, let us know, and we’ll investigate).

It turns out that the software is  getting a RootFrame_Obscured message, when he presses the lock screen.

When the camera button is pressed, an Application_Deactivated event is raised, my state is stored, and that’s the last my code ever sees of any execution time.

The program does have a background XNA thread for audio that’s raising a System.Threading.ThreadAbortException in Microsoft.Xna.Framework.dll before it exits however.

Any suggestions?

1 comment:

  1. OK, simplest repro ever:

    Create a new blank project, and Change Application_Launching to this:

    // Code to execute when the application is launching (eg, from Start)
    // This code will not execute when the application is reactivated
    private void Application_Launching(object sender, LaunchingEventArgs e)
    PhoneApplicationService.Current.ApplicationIdleDetectionMode =

    Now build and run. Press the off button on your phone. Press it again, and you'll see your app is still running.

    Press off again, and then press the camera button til it goes into camera mode.

    Now press the back button, and hey presto, you're on the start screen and your app is gone!