07 wp7 application lifecycle

19
Applicat ion Lifecycl e Jason Lee Ethos Technologie

Upload: tao-wang

Post on 21-May-2015

1.986 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: 07 wp7   application lifecycle

ApplicationLifecycle

Jason LeeEthos Technologies

Page 2: 07 wp7   application lifecycle

Agenda• Interruptions & User Expectations• Application Lifecycle• Tombstoning• Lifecycle Events• Resource Management• Play Time• Q & A

Page 3: 07 wp7   application lifecycle

Interruptions• Interruption comes from

• A user action (i.e. press the start button)• An external event (an incoming phone call)• An internal action (i.e. taking a photo, choosing a contact)

• Interruption characteristics• Interruptions are not predictable• Interruptions tend to happen frequently

Page 4: 07 wp7   application lifecycle

User Expectations• Phone and Applications

• Phone is resource-constrained device, therefore we need to consume resources carefully

• Phone is different from Desktop OS, which can hold multiple windows running processes simultaneously

• However…• A user expects the application to be able to remain in the state where it

was left• Microsoft development guideline requires application to provide such

illusions that it keeps running continuously until it is get killed

Page 5: 07 wp7   application lifecycle

Running

Application Lifecycle

Dormant

Phone resources detachedThreads & Timers suspendedBut app instance remains in memory

Tombstoned

Dead, and no longer lives in memory.But with somethingcarved on a Tombstone

Deactivated

Activatede.Preserved == true

Fast App Resume

Activatede.Preserved == false

You Will See Resuming Process Bar

Deactivated

Page 6: 07 wp7   application lifecycle

Tombstoning• When an app is tombstoned, it means

• The app is dead• Some relevant data is saved by System for the app/page, which is called

State information

• When user navigates back• System restarts the application, passes applications state back to the App• System navigates to the very page where it was left, passes page state

back to the Page

• Developers should• Write code to save state before the app gets tombstoned• Write code to restore state after the app is reactivated from tombstoned

Page 7: 07 wp7   application lifecycle

Lifecycle Events - App• Application_Launching

• Fired when the application is started• Not fired when the application is reactivated• Load app settings/configuration

• Application_Activated• Fired when the application is reactivated (brought to foreground)• Not fired when the application is started• Restore app state if tombstoned

• Application_Deactivated• Fired when the application is deactivated (sent to background)• Not fired when the application is closed• Save app state as needed

• Application_Closing• Fired when the application is closing (i.e. user presses Back key)• Not fired when the application is deactivated• Save app settings/configuration

Page 8: 07 wp7   application lifecycle

Lifecycle Events - Page• OnNavigatedTo

• Fired when the application is started• Not fired when the application is reactivated• Restore page state if tombstoned

• OnNavigatedFrom• Fired when the application is deactivated (sent to background)• Not fired when the application is deactivated• Save page state as needed

Page 9: 07 wp7   application lifecycle

Code Sample - 1• Application_Launching

• Load app settings/configuration

Page 10: 07 wp7   application lifecycle

Code Sample - 2• Application_Closing

• You have only 10 seconds to finish all job• If you’ve got complex data to save, it’s recommended to save your data

while the app is running at appropriate points

Page 11: 07 wp7   application lifecycle

Code Sample - 3• Application_Deactivated

• Save app state as needed

Page 12: 07 wp7   application lifecycle

Code Sample - 4• Application_Activated

• Restore app state if tombstoned

Page 13: 07 wp7   application lifecycle

Time Limits

Timer Limit Details

Startup 10 Seconds From Application start until Page's OnNavigatedTo event completes

Exit 10 Seconds From user hits Back key to Closing event completes

Return 10 SecondsFrom user invokes a return (either hitting Back key or returning from a Chooser) to Page's OnNavigatedTo event completes

Leave 10 SecondsFrom user leaves an application (i.e. hitting Start key, Search key, Locking screen) to Deactivated event completes

Page 14: 07 wp7   application lifecycle

Resource Management - 1

XNA Audio Paused

Sensors Notifications suppressed

Networking Cancelled

Sockets Disconnected

MediaElement Disconnected

Camera Disposed

- You may release phone resources, but not necessarily, the framework is doing it anyway- You MUST Save app/page state

Deactivating App

Page.OnNavigatedFrom

App.Deactivated

Framework:Detach Resources

Framework:Suspend Timers and Threads

Dormant App

Page 15: 07 wp7   application lifecycle

Resource Management - 2

Dormant App

XNA Audio Resumed

Sensors Notifications resumed

Networking Completed with Cancellation

Sockets -

MediaElement -

Camera -

- MediaElement : Reset Source/Position- Socket : Reconnect- Camera: Recreate Object- Restore app state if tombstoned

Framework:Resume Timers and Threads

Framework:Attach Resources

App.Activated

Page.OnNavigatedTo

Running App

Page 16: 07 wp7   application lifecycle

Take It Serious• It is required, not just recommended !

• Microsoft tries its best to keep apps in the line, providing consistent user experience to end users.

• It is about money !• If your app does not handle lifecycle issues, then it will be disqualified to

be published on marketplace.

Page 17: 07 wp7   application lifecycle

Play Time !• Goals

• To understand various lifecycle events and orders of occurring under different situations

• To be able to store and retrieve state information• To understand how tombstoning works

Page 18: 07 wp7   application lifecycle

Tip• To test tombstoning on emulator

Page 19: 07 wp7   application lifecycle

! & ?

Thank You ! Any Questions ?