LP Pinsonneault blog's

Windows 8, Windows Phone, ...

NAVIGATION - SEARCH

Windows Phone 7 – Suspend mode

Recently i was publishing an updated version of an application on the Marketplace for Windows Phone 7, and my update failed the testing process.

Why?

Comments: The user isuse  presented with an error message when the location services are disabled on the device. The error
message that is displayed is not a user friendly message.
Steps to reproduce:
1. Turn on location service on device.
2. Launch the application and select a location
on the venues page.
3. Swipe to the map page and select view map.
4. When map is loaded press the Start button on the device. 5. Go to the settings of the device and turn off location service.
6. Press the Back button from the Start screen of the device to reactivate the application.
7. Notice a non-user friendly error notification appears.

Real reason
In reality the problem is not related with the location services. Because i don’t use the location service (i only use the Bing Map for display only).  In fact, the real problem it’s that i forgot to handle the Deactivated event and the Activated event.

Why do we have to handle the Activated and Deactivated event?
Windows Phone 7 doesn’t support multiple application running at the same time (except for some application approve by Microsoft). But when your application is running, for different reason (incoming phone call, the user click the start button, …) the application can be suspended. To eliminate some issues you should handle those event and make sure you persist important information.

gg266441_788be805-086f-49cf-9911-fc638a953c92_png(en-us)

One of the best place to handle these events is in the App.xaml. To do so you need to declare the events in the xaml code.

<Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="PhoneApplicationService_Launching"    
            Closing="PhoneApplicationService_Closing"
            Activated="PhoneApplicationService_Activated"    
            Deactivated="PhoneApplicationService_Deactivated" />
    </Application.ApplicationLifetimeObjects>

In the Activated event, you can store some data in the the Microsoft.Phone.Shell.PhoneApplicationService.Current.State dictionary. And in the Deactivated event, we can retrieve that information.

Conclusion
Make sure to test any scenario that a user may face. Currently, the testing process that Microsoft implemented is pretty exhaustive (which is good because it help ensure that the application in the Marketplace won’t crash).

Reference
http://msdn.microsoft.com/en-us/wp7trainingcourse_applicationlifetimewp7lab_topic2.aspx
http://bolingconsulting.com/blog/?p=46

Regards,

LP