Top Banner
Understanding Application Lifecycle & State Management Danilo Diaz, Developer Evangelist Lindsay Lindstrom, Developer Evangelist http://blogs.msdn.com/lindsay
14

runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Dec 16, 2015

Download

Documents

Susan Hay
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Understanding Application Lifecycle & State ManagementDanilo Diaz, Developer EvangelistLindsay Lindstrom, Developer Evangelisthttp://blogs.msdn.com/lindsay

Page 2: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

(Tue 4/3 10AM PST) - http://aka.ms/HackReadyPhone1

Introduction to the Windows Phone Platform(Thur 4/5 10AM PST) - http://aka.ms/HackReadyPhone2

Working with Internal & External Data in Windows Phone(Tue 4/10 10AM PST) - http://aka.ms/HackReadyPhone3

Understanding Windows Phone’s Application Lifecycle and State Management(Thur 4/12 10AM PST) - http://aka.ms/HackReadyPhone4

Working with Windows Phone Sensors and Other APIs?(Tue 4/17 10AM PST) - http://aka.ms/HackReadyPhone5

Enhancing the User Experience and App Usability with Live Tiles, Push Notifications, and Background Agents(Thur 4/19 10AM PST) - http://aka.ms/HackReadyPhone6

Enhancing Performance and Application Testing(Tue 4/24 10AM PST) - http://aka.ms/HackReadyPhone7

Everything You Need to Know About Releasing Your Apps

Page 3: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

What we are building…

Page 4: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Application Lifecycle - Dormant

running

deactivated

dormant

activated

Phone resources detachedThreads & timers suspended

Fast App Resume

Save State!State preserved!e.IsApplicationInstancePreserved== true

Page 5: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Application Lifecycle - Tombstoned

running

deactivated

dormant Phone resources detachedThreads & timers suspended

Restore state!e.IsApplicationInstancePreserved == false

Resuming .. .

Tombstone the oldest app

Tombstoned

activated

Page 6: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Methods & Events

Page 7: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Finding the Resume type

• The Activation handler can test a flag to determine the type of resume taking place

private void Application_Activated(object sender, ActivatedEventArgs e){ if (e.IsApplicationInstancePreserved) { // Dormant - objects in memory intact } else { // Tombstoned - need to reload }}

Page 8: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Deactivation Resource Management

Deactivated App

PhoneApplicationPage.OnNavigatedFrom

PhoneApplicationService.Deactivated

Framework:Detach Resources

Framework:Suspend Timers and

Threads

Dormant App

MediaPlayer.PauseMediaElement.Pause

SoundEffectInstance.PauseVibrateController.StopPhotoCamera.Dispose

Save page/global state

XNA Audio Paused

Sensors Notifications suppressed

Networking Cancelled

Sockets Disconnected

MediaElement

Disconnected

Camera Disposed

Page 9: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Activation Resource Management

MediaElement.Source/Position/Play

Socket.ConnectAsyncnew PhotoCamera/VideoCamera

Restore app state if tombstoned

Running App

PhoneApplicationPage.OnNavigatedTo

PhoneApplicationService.Activated

Framework:Attach Resources

Framework:Resume Timers and

Threads

Dormant App

XNA Audio Resumed

Sensors Notifications resumed

Networking Completed with Cancellation

Sockets -

MediaElement

-

Camera -

Page 10: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Isolated Storage vs State Storage• Isolated storage is so called because the

data for an application is isolated from all other applications • It can be used as filestore where an application

can store folders and files• It is slow to access, since it is based on NVRAM

technology• It can also be used to store name/value pairs, e.g.

program settings• State storage is so called because it is used

to hold the state of an application• It can be used to store name/value pairs which

are held in memory for dormant or tombstoned applications

• It provides very quick access to data

Page 11: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Demo

• With No Storage• With Storage• Fully Working

Captain’s Log

Page 12: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Fast App Switching & Tombstoning Review• Only one Windows Phone application is

Active at any time• The Start and Back buttons on the phone

are used to start new applications and return to previously used ones

• If an application is replaced by another it is either made Dormant (still in memory but not running) or Tombstoned (removed from memory)

• Applications must use populate methods provided in the App.xaml.cs class to save and retrieve state information when appropriate• State can be stored in memory for quick reload

and in isolated storage which serve as a permanent store

Page 13: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Resources• create.msdn.com• http://ux.artu.tv/• http://silverlight.codeplex.com• http://coding4fun.codeplex.com• http://create.msdn.com/en-US/

education/catalog/• http://smallandmighty.net/blog/windows-

phone-design-resources• http://smallandmighty.net/blog/windows-

phone-resources

Page 14: runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! e.IsApplicationInstancePreserved.

Thank You

Lindsay [email protected]/lindsay@LindsayInPhilly

Danilo [email protected]@DaniDiaz