How to simulate the lock screen for Windows Phone 8

July 21, 2014

This topic describes how you can simulate locking and unlocking the phone while you’re running your app on the emulator or a connected device to test how your app responds.

In ordinary apps, you can test how your app restores its state after it has been deactivated. An app that targets Windows Phone 8 or Windows Phone OS 7.1 is deactivated when the lock screen engages. Instead of being terminated, the app goes into a dormant state, unless you have enabled tombstoning while debugging. (To enable tombstoning when you test your app, in the Project Designer, on the Debug page, select Tombstone upon deactivation while debugging.) When the phone is unlocked, the app typically is activated, and then restores its state to the same state in which it was before the lock screen engaged. For more information, see App activation and deactivation for Windows Phone 8.

In specially configured apps that use location services, you can test how your app continues to run in the background when the lock screen is engaged. You can configure an app that targets Windows Phone 8 and that uses location services to continue to run in the background, even when the lock screen is engaged. This might be useful for long-running apps such as a navigation app that continually updates maps and directions, or an exercise app that tracks how far you have run. For more information, see How to run location-tracking apps in the background for Windows Phone 8.

TipTip:

To enable the lock screen in the emulator, you can also press the F12 key on your computer keyboard twice. The F12 key emulates the phone’s power button. For more info, see How to use the computer keyboard with the emulator for Windows Phone 8.

This topic contains the following sections.

In an ordinary app, the following events occur.

  • When the phone is locked, first the Obscured event is raised, and then the Deactivated event is raised. You can check the IsLocked property of the ObscuredEventArgs to determine whether the lock screen caused the deactivation.

  • When the phone is unlocked, the Activated event is raised, and then the Unobscured event is raised.

In an app that use location services and that is specially configured to run continuously in the background, the following events occur.

  • When the phone is locked, the Obscured event is raised. You can check the IsLocked property of the ObscuredEventArgs to determine whether the lock screen obscured the app.

  • When the phone is unlocked, the Unobscured event is raised.

The following illustration shows the options that are available in the Simulation Dashboard in Visual Studio for locking or unlocking the screen.

Simulation dashboard option for locking the screen

The Lock Screen option buttons in the Simulation Dashboard are not synchronized with the actual screen state of the target device. For example, if you’re testing your app on a phone and you manually engage or disengage the lock screen on the phone itself, the state of the Lock Screen option buttons on the Simulation Dashboard is not updated.

To simulate locking or unlocking the phone

  1. Run your app on the emulator or a connected device, with or without debugging.

    Or, run your app with app monitoring and profiling to measure its quality and performance. For more information about app monitoring and profiling, see Windows Phone Application Analysis for Windows Phone 8.

  2. In Visual Studio, on the Tools menu, open Simulation Dashboard. Find the Lock Screen section of the dashboard.

  3. To engage the lock screen and lock the phone, select Locked.

  4. Test how your app handles deactivation.

  5. To disengage the lock screen and unlock the phone, select Unlocked.

  6. Test how your app handles activation.

Show:
© 2014 Microsoft