SlideShare a Scribd company logo
1 of 45
Oliver Scheer
Senior Technical Evangelist
Microsoft Deutschland
http://the-oliver.com
Application
Lifecycle
• Windows Phone 8 program lifecycle
• Launching and Closing
• Deactivating and Activating
• Dormant and Tombstoned applications
• Simulation Dashboard
• Idle Detection on Windows Phone
• Detecting Obscured events
• Fast Application Resume
Agenda
In This Session…
3/18/20142
• Lifecycle design
• Page Navigation and the Back Stack
Windows Phone Program
Lifecycle
Tombstoned
• Windows Phone apps transition between different
application states
• Apps are launched from Start Screen icon, apps menu
or from deep link
• User may close apps
• The OS will suspend your app if it loses focus
Suspended apps may be tombstoned
• Apps may be reactivated from a suspended state
• When the user starts a new instance of your app, any
suspended instance is discarded
• In Windows Phone 8.0, you can enable Fast Application
Resume to relaunch the suspended instance
Windows Phone Application Lifecycle
3/18/2014
Not running
Running
LaunchingClosing
DeactivatingActivating
Dormant
Application Lifecycle Events
• The Windows Phone application environment notifies an application about lifecycle events
through a set of events
• In the project templates, the events are already wired up in App.xaml and the event handler
methods are in the App.xaml.cs file
• Initially the event handler methods are empty
// 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)
{
}
Demo 1: Launching
and Closing
Launching and Closing – what we have seen
• When a Windows Phone 8 application is started the
Application_Launching event handler method is called
• Good place to load content from backing store
• When a Windows Phone 8 application is ended the
Application_Closing event handler method is called
• Good place to save content in backing store
• The debugger will keep running even when your application is
“stopped”
• This makes it easier to debug start and stop behaviour
• But you need to stop it yourself to work on your code..
3/18/2014
Not running
Running
Application_
Launching
Application_
Closing
Application Deactivation and Reactivation
• If you are from a Windows desktop background this behavior will make perfect sense
• Windows desktop applications can subscribe to events that are fired when the program
starts and ends
• However, Windows Phone applications operate on a smartphone and the OS imposes
restrictions designed to save battery life and ensure a good end-user experience
• At any give time only one applications is in the foreground
• Users may deactivate their applications and reactivate them later
• Applications have to deal with being activated and deactivated
3/18/20148
Demo 2: Deactivating
and Activating
Dormant applications
• The user can make your application dormant at any time
• They could launch another program from the start screen
or the Programs menu
• The Application_Deactivated method is called in this situation
• External events may also make your application dormant
• If a phone call is received when your program is running
it will be made dormant
• If the lock screen shows after a period of inactivity
• A user may return to your application and resume it at a
later time
3/18/2014
Tombstoned
Running
DeactivatingActivating
Dormant
Dormant applications
• The user can make your application dormant at any time
• They could launch another program from the start screen
or the Programs menu
• The Application_Deactivated method is called in this situation
• External events may also make your application dormant
• If a phone call is received when your program is running
it will be made dormant
• If the lock screen shows after a period of inactivity
• A user may return to your application and resume it at a
later time
3/18/2014
Tombstoned
Running
DeactivatingActivating
Dormant
There is no guarantee that your application
will ever be resumed if it is made dormant
Dealing with Dormant
• When your application is made dormant it must do as much data persistence as if it was
being closed
• Because Application_Deactivated and Application_Closing will mean the same thing if
the user never comes back to your program
• Your application can run for up to 5 seconds to perform this tidying up
• After that it will be forcibly removed from memory
• When an application is resumed from dormant it will automatically resume at the page
where it was deactivated
• This behaviour is managed by the operating system
• All objects are still in memory exactly as they were at the moment the app was
suspended
3/18/201412
Reactivating from Dormant
ActiveDormant
Resuming an Application – Fast Application Switching
• The user can resume a suspended application by
‘unwinding’ the application history stack by continually
pressing the ‘Back’ key to close applications higher up the
history stack, until the suspended application is reached
• The Back button also has a “long press” behaviour
• This allows the user to select the active application from the
stack of interrupted ones
• Screenshots of all the applications in the stack are displayed
and the user can select the one that they want
• The application is brought directly into the foreground if it is
selected by the user
• On Windows Phone 8, the app history stack can hold up to 8
applications
14
From Dormant to Tombstoned
• An application will be held dormant in memory alongside other
applications
• If the operating system becomes short of memory it will discard the cached
state of the oldest dormant application
• This process is called “Tombstoning”
• The page navigation history and a special cache called the state
dictionaries are maintained for a tombstoned application
• When a dormant application is resumed the application resumes
running just where it left off
• When a tombstoned application is resumed, it restarts at the correct
page but all application state has been lost – you must reload it
• An application can determine which state it is being activated from
3/18/201415
Tombstoned
Running
DeactivatingActivating
Dormant
Reactivating from Tombstoned
ActiveDormantTombstoned
Resumed from Dormant or Tombstoned?
• You can also check a flag to see if a the application is being resumed from dormant or
tombstoned state
private void Application_Activated(object sender, ActivatedEventArgs e)
{
if (e.IsApplicationInstancePreserved)
{
// Dormant - objects in memory intact
}
else
{
// Tombstoned - need to reload
}
}
Debugging Tombstoning
• You can force an application to be “tombstoned”
(removed from memory) when it is made
dormant by setting this in Visual Studio
• You should do this as part of your testing regime
• You can also use the Simulation Dashboard to
show the lock screen on the emulator which will
also cause your application to be made dormant
3/18/201418
Demo 3: Dormant vs
Tombstoned
States and Tombstones
• When an application is resumed from Dormant, it resumes exactly where it left off
• All objects and their state is still in memory
• You may need to run some logic to reset time-dependent code or networking calls
• When an application is resumed from Tombstoned, it resumes on the same page where it left
off but all in-memory objects and the state of controls has been lost
• Persistent data will have been restored, but what about transient data or “work in
progress” at the time the app was suspended?
• This is what the state dictionaries are for, to store transient data
• State dictionaries are held by the system for suspended applications
• When a new instance of an application is launched the state dictionaries are empty
• If there is a previous instance of the application that is suspended, standard behaviour is
that the suspended instance – along with its state dictionaries - is discarded
3/18/201420
The Application State dictionary
• Transient data for a tombstoned application may be stored in the application state
dictionary
• This can be set in the Application_Deactivated method and then restored to memory
when the application is activated from tombstoned
• This means that the Application_Deactivated method has two things to do:
• Store persistent data in case the application is never activated again
• Optionally store transient data in the application state dictionary in case the user comes
back to the application from a tombstoned state
PhoneApplicationService.Current.State["Url"] = "www.robmiles.com";
Saving Transient Data on Deactivation
• Use the Page State dictionary to store transient data at page scope such as data the user has
entered but not saved yet
• Page and Application State are string-value dictionaries held in memory by the system but
which is not retained over reboots
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back
&& e.NavigationMode != System.Windows.Navigation.NavigationMode.Forward)
{
// If we are exiting the page because we've navigated back or forward,
// no need to save transient data, because this page is complete.
// Otherwise, we're being deactivated, so save transient data
// in case we get tombstoned
this.State["incompleteEntry"] = this.logTextBox.Text;
}
}
Restoring Transient Data on Reactivation
• In OnNavigatedTo, if the State dictionary contains the value stored by OnNavigatedFrom,
then you know that the page is displaying because the application is being reactivated
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// If the State dictionary contains our transient data,
// we're being reactivated so restore the transient data
if (this.State.ContainsKey("incompleteEntry"))
{
this.logTextBox.Text = (string)this.State["incompleteEntry"];
}
}
Demo 4: Using State
Dictionaries
Running Under Lock
Screen on Windows
Phone
Windows Phone Idle Detection
• The Windows Phone operating system will detect when an application is idle
• When the phone enters idle state the lock screen is engaged
• The user can configure the timeout value, or even turn it off
• When an application is determined to be idle it will be Deactivated and then Activated
when the user unlocks the phone again
• An application disable this behaviour, so that it is able to run underneath the lock screen
3/18/201426
Windows Phone Idle Detection
• The Windows Phone operating system will detect when an application is idle
• When the phone enters idle state the lock screen is engaged
• The user can configure the timeout value, or even turn it off
• When an application is determined to be idle it will be Deactivated and then Activated
when the user unlocks the phone again
• An application disable this behaviour, so that it is able to run underneath the lock screen
This is strong magic. It gives you the means to create a “battery flattener”
which users will hate. Use it with care, read the guidance in the
documentation and follow the checklists.
3/18/201427
Disabling Idle Detection
• This statement disables idle detection mode for your application
• It will now continue running under the lock screen
• There will be no Activated or Deactivated messages when the phone locks because the
application is timed out
• Note that your application will still be deactivated if the users presses the Start button
• Disabling idle detection is not a way that you can run two applications at once
PhoneApplicationService.Current.ApplicationIdleDetectionMode =
IdleDetectionMode.Disabled;
Detecting “Obscured” events
• Your application can connect to the Obscured event for the enclosing frame
• This will fire if something happens (Toast message, Lock Screen, Incoming call) that will
obscure your frame
• It also fires when the obscuring item is removed
• You can use the ObscuredEventArgs value to detect the context of the call
App.RootFrame.Obscured += RootFrame_Obscured;
...
void RootFrame_Obscured(object sender, ObscuredEventArgs e)
{
}
Simulation Dashboard
• The Simulation Dashboard is one of the tools
supplied with Visual Studio 2012
• It lets you simulate the environment of your
application
• It also lets you lock and unlock the screen of the
emulator phone
• This will cause Deactivated and Activated events to
fire in your program
3/18/201430
Fast Application Resume
Fast Application Resume
• By default a fresh instance of your application is always launched when the user starts a
new copy from the programs page or a deep link in a secondary tile or reminder, or via
new features such as File and Protocol associations or launching by speech commands
• This forces all the classes and data to be reloaded and slows down activation
• Windows Phone 8 provides Fast Application Resume, which reactivates a dormant
application if the user launches a new copy
• This feature was added to enable background location tracking
• You can take advantage of it to reactivate a dormant application instead of launching a
new instance
3/18/201441
Demo 6: Fast
Application Resume
Enabling FAR in PropertiesWMAppManifest.xml
• This is how FAR is selected
• You have to edit the file by hand, there is no GUI for this
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml">
<BackgroundExecution>
<ExecutionType Name="LocationTracking" />
</BackgroundExecution>
</DefaultTask>
</Tasks>
The Two Flavors of FAR
• Oddly, you enable FAR by registering your app as a “LocationTracking” app – whether or
not you actually track location!
• If you have marked your app LocationTracking *and* you actively track location by using
the GeoCoordinateWatcher or GeoLocator classes:
• App continues to run in the background if it is deactivated while actively tracking
• If re-launched from the Apps menu or via a Deep Link, the existing instance will be reactivated if it is
running in the background or fast resumed if it is dormant
• More on this in the Maps and Location Session!
• If you have marked your app LocationTracking but you don’t have any Geolocation code in
your app, then your app is one that can be fast resumed
• When deactivated, your app is suspended just like normal
• But when your app is relaunched and the previous instance is currently dormant, that previous
instance is fast resumed
3/18/201444
Standard App Relaunch Behavior
ActiveDormant
‘True’ Background Location Tracking Behavior
ActiveDormant
Location
Tracking
FAR-enabled App Behavior
ActiveDormant
Location
Tracking
Sounds Great! So Why Don’t I Use FAR With All My Apps?
• You need to be very careful on protecting the user experience with respect to page
navigation
• Deep Link activation
• On non FAR-enabled apps, if you launch an app to ‘Page2’, then ‘Page2’ is the only page
in the page backstack, and pressing Back closes the app
• For FAR-enabled apps, if you launch an app to ‘Page2’, but there was a suspended
instance containing a page history backstack of ‘MainPage’, ‘Page1’, ‘Page2’, ‘Page3’ then
the newly launched app will end up with a backstack of ‘MainPage’, ‘Page1’, ‘Page2’,
‘Page3’, ‘Page2’
• What should the user experience be here?
3/18/201448
App List/Primary Tile Behavior of FAR-enabled Apps
• Similarly, the user expectation when launching an app from an application tile on the Start
Screen or from the Apps List is that the app will launch at the home page of the app
• This is what will happen for non FAR-enabled apps
• This is what will happen even for FAR-enabled apps if there is no suspended instance at the time the
app is launched
• Since your app can now resume, what should the user experience be?
• Should you always launch on the home page to match previous behaviour of Windows Phone apps?
• Or should you resume at the page the user was last on?
• If you resume at the last page the user was on, think about how the user will navigate to the home
page; good idea to put a home icon on the app bar of the page the user lands on
3/18/201449
Detecting Resume in a FAR-enabled App
• In a true Background Location Tracking app, when the app is sent to the background it
continues to run
• App will get PhoneApplicationService.RunningInBackground event instead of the
Application_Deactivated event
• When an app enabled for Fast App Resume (aka FAR) is relaunched from the App List or a
Deep Link:
• Page on the top of the backstack gets navigated with NavigationMode.Reset
• Next, the page in the new launch url will be navigated to with NavigationMode.New
• You can decide whether to unload the page backstack or not, or maybe cancel the
navigation to the new page
3/18/201450
private void InitializePhoneApplication()
{
...
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
...
}
private void CheckForResetNavigation(object sender, NavigationEventArgs e)
{
// If the app has received a 'reset' navigation, then we need to check
// on the next navigation to see if the page stack should be reset
if (e.NavigationMode == NavigationMode.Reset)
RootFrame.Navigated += ClearBackStackAfterReset;
}
Clearing Previously Launched Pages on Fast App Resume
Add Logic to App.Xaml.cs to Check for Reset Navigation (Behavior Already Implemented in Project Templates)
3/18/2014Microsoft confidential51
private void InitializePhoneApplication()
{
...
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
...
}
private void CheckForResetNavigation(object sender, NavigationEventArgs e)
{
// If the app has received a 'reset' navigation, then we need to check
// on the next navigation to see if the page stack should be reset
if (e.NavigationMode == NavigationMode.Reset)
RootFrame.Navigated += ClearBackStackAfterReset;
}
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
Clearing Previously Launched Pages on Fast App Resume
Add Logic to App.Xaml.cs to Check for Reset Navigation (Behavior Already Implemented in Project Templates)
3/18/2014Microsoft confidential52
Review
• Programs can be Launched (from new) or Activated (from Dormant or Tombstoned)
• The operating system provides a state storage object and navigates to the correct page
when activating an application that has been running, but you have to repopulate forms
• Programs can run behind the Lock Screen by disabling Idle Timeout – but this is potentially
dangerous (and apps must deal with the Obscured event in this situation)
• The system maintains a Back Stack for application navigation. This must be managed to
present the best user experience when applications are started in different ways
• Applications are normally launched anew each time they are started from the Programs
page, but it is now possible to restart a suspended instance using Fast Application Resume
• YOU MUST PLAN YOUR LAUNCHING AND BACK STACK BEHAVIOUR FROM THE START
3/18/201453
The information herein is for informational
purposes only an represents the current view of
Microsoft Corporation as of the date of this
presentation. Because Microsoft must respond
to changing market conditions, it should not be
interpreted to be a commitment on the part of
Microsoft, and Microsoft cannot guarantee the
accuracy of any information provided after the
date of this presentation.
Š 2012 Microsoft Corporation.
All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION
IN THIS PRESENTATION.

More Related Content

What's hot

Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksMohammad Vaseem Akaram
 
Physical layer ppt
Physical layer pptPhysical layer ppt
Physical layer pptNajam Khattak
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternBharat Rathore
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
Reference models in Networks: OSI & TCP/IP
Reference models in Networks: OSI & TCP/IPReference models in Networks: OSI & TCP/IP
Reference models in Networks: OSI & TCP/IPMukesh Chinta
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanagerArati Gadgil
 
Nested loops
Nested loopsNested loops
Nested loopsNeeru Mittal
 
language , grammar and automata
language , grammar and automatalanguage , grammar and automata
language , grammar and automataElakkiyaS11
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR Zahid Parvez
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Mohammad Ilyas Malik
 
Transport services
Transport servicesTransport services
Transport servicesNavin Kumar
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMRajendran
 
Windows programming ppt
Windows programming pptWindows programming ppt
Windows programming pptSAMIR CHANDRA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaRahulAnanda1
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structuresMukesh Chinta
 
TOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFATOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFAMohammad Imam Hossain
 
Data link layer
Data link layer Data link layer
Data link layer Mukesh Chinta
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 

What's hot (20)

Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
Physical layer ppt
Physical layer pptPhysical layer ppt
Physical layer ppt
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Reference models in Networks: OSI & TCP/IP
Reference models in Networks: OSI & TCP/IPReference models in Networks: OSI & TCP/IP
Reference models in Networks: OSI & TCP/IP
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Nested loops
Nested loopsNested loops
Nested loops
 
language , grammar and automata
language , grammar and automatalanguage , grammar and automata
language , grammar and automata
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
 
Transport services
Transport servicesTransport services
Transport services
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
Windows programming ppt
Windows programming pptWindows programming ppt
Windows programming ppt
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
TOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFATOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFA
 
Data link layer
Data link layer Data link layer
Data link layer
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 

Similar to Windows Phone 8 - 5 Application Lifecycle

Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9hitesh chothani
 
Windows Phone 8 Fundamental
Windows Phone 8 FundamentalWindows Phone 8 Fundamental
Windows Phone 8 FundamentalNguyên Phấm
 
Android Performance Best Practices
Android Performance Best Practices Android Performance Best Practices
Android Performance Best Practices Amgad Muhammad
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
13.Windows Phone Store
13.Windows Phone Store13.Windows Phone Store
13.Windows Phone StoreNguyen Tuan
 
Sinergija 11 WP7 Mango multitasking and “multitasking”
Sinergija 11   WP7 Mango multitasking and “multitasking”Sinergija 11   WP7 Mango multitasking and “multitasking”
Sinergija 11 WP7 Mango multitasking and “multitasking”Catalin Gheorghiu
 
Windows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreWindows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreOliver Scheer
 
Windows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsWindows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsOliver Scheer
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile DevicesYnon Perek
 
AISEC 12 april 2012 WP 7.1.1
AISEC 12 april 2012  WP 7.1.1AISEC 12 april 2012  WP 7.1.1
AISEC 12 april 2012 WP 7.1.1Catalin Gheorghiu
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
Bcsf13a019_mcqs_ead
Bcsf13a019_mcqs_eadBcsf13a019_mcqs_ead
Bcsf13a019_mcqs_eadMarYam IqBal
 
07 wp7 application lifecycle
07 wp7   application lifecycle07 wp7   application lifecycle
07 wp7 application lifecycleTao Wang
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycleSV.CO
 
Whats different in android L, M, N and O
Whats different in android L, M, N and OWhats different in android L, M, N and O
Whats different in android L, M, N and OPietro F. Maggi
 
Deploying to cloud hub
Deploying to cloud hubDeploying to cloud hub
Deploying to cloud hubSon Nguyen
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
Windows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesWindows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesOliver Scheer
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 

Similar to Windows Phone 8 - 5 Application Lifecycle (20)

Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9
 
Windows Phone 8 Fundamental
Windows Phone 8 FundamentalWindows Phone 8 Fundamental
Windows Phone 8 Fundamental
 
Android Performance Best Practices
Android Performance Best Practices Android Performance Best Practices
Android Performance Best Practices
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
13.Windows Phone Store
13.Windows Phone Store13.Windows Phone Store
13.Windows Phone Store
 
Sinergija 11 WP7 Mango multitasking and “multitasking”
Sinergija 11   WP7 Mango multitasking and “multitasking”Sinergija 11   WP7 Mango multitasking and “multitasking”
Sinergija 11 WP7 Mango multitasking and “multitasking”
 
Windows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreWindows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone Store
 
Windows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsWindows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background Agents
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
 
AISEC 12 april 2012 WP 7.1.1
AISEC 12 april 2012  WP 7.1.1AISEC 12 april 2012  WP 7.1.1
AISEC 12 april 2012 WP 7.1.1
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Bcsf13a019_mcqs_ead
Bcsf13a019_mcqs_eadBcsf13a019_mcqs_ead
Bcsf13a019_mcqs_ead
 
07 wp7 application lifecycle
07 wp7   application lifecycle07 wp7   application lifecycle
07 wp7 application lifecycle
 
Windows 8 Client Part 2 "The Application internals for IT-Pro's"
Windows 8 Client Part 2 "The Application internals for IT-Pro's"  Windows 8 Client Part 2 "The Application internals for IT-Pro's"
Windows 8 Client Part 2 "The Application internals for IT-Pro's"
 
App anatomy and life cycle
App anatomy and life cycleApp anatomy and life cycle
App anatomy and life cycle
 
Whats different in android L, M, N and O
Whats different in android L, M, N and OWhats different in android L, M, N and O
Whats different in android L, M, N and O
 
Deploying to cloud hub
Deploying to cloud hubDeploying to cloud hub
Deploying to cloud hub
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
Windows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesWindows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone Resources
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 

More from Oliver Scheer

Windows Phone 8 - 16 Wallet and In-app Purchase
Windows Phone 8 - 16 Wallet and In-app PurchaseWindows Phone 8 - 16 Wallet and In-app Purchase
Windows Phone 8 - 16 Wallet and In-app PurchaseOliver Scheer
 
Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsOliver Scheer
 
Windows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechWindows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechOliver Scheer
 
Windows Phone 8 - 13 Near Field Communcations and Bluetooth
Windows Phone 8 - 13 Near Field Communcations and BluetoothWindows Phone 8 - 13 Near Field Communcations and Bluetooth
Windows Phone 8 - 13 Near Field Communcations and BluetoothOliver Scheer
 
Windows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationWindows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationOliver Scheer
 
Windows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationWindows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationOliver Scheer
 
Windows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsWindows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsOliver Scheer
 
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsWindows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsOliver Scheer
 
Windows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseWindows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseOliver Scheer
 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageOliver Scheer
 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingOliver Scheer
 
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentWindows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentOliver Scheer
 
Windows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsWindows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsOliver Scheer
 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageOliver Scheer
 
Windows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsWindows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsOliver Scheer
 

More from Oliver Scheer (15)

Windows Phone 8 - 16 Wallet and In-app Purchase
Windows Phone 8 - 16 Wallet and In-app PurchaseWindows Phone 8 - 16 Wallet and In-app Purchase
Windows Phone 8 - 16 Wallet and In-app Purchase
 
Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and Maps
 
Windows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechWindows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using Speech
 
Windows Phone 8 - 13 Near Field Communcations and Bluetooth
Windows Phone 8 - 13 Near Field Communcations and BluetoothWindows Phone 8 - 13 Near Field Communcations and Bluetooth
Windows Phone 8 - 13 Near Field Communcations and Bluetooth
 
Windows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationWindows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network Communication
 
Windows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationWindows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App Communication
 
Windows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsWindows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push Notifications
 
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsWindows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
 
Windows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseWindows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local Database
 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and Storage
 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async Programming
 
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentWindows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
 
Windows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsWindows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 Applications
 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and Storage
 
Windows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsWindows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 Applications
 

Recently uploaded

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Windows Phone 8 - 5 Application Lifecycle

  • 1. Oliver Scheer Senior Technical Evangelist Microsoft Deutschland http://the-oliver.com Application Lifecycle
  • 2. • Windows Phone 8 program lifecycle • Launching and Closing • Deactivating and Activating • Dormant and Tombstoned applications • Simulation Dashboard • Idle Detection on Windows Phone • Detecting Obscured events • Fast Application Resume Agenda In This Session… 3/18/20142 • Lifecycle design • Page Navigation and the Back Stack
  • 4. Tombstoned • Windows Phone apps transition between different application states • Apps are launched from Start Screen icon, apps menu or from deep link • User may close apps • The OS will suspend your app if it loses focus Suspended apps may be tombstoned • Apps may be reactivated from a suspended state • When the user starts a new instance of your app, any suspended instance is discarded • In Windows Phone 8.0, you can enable Fast Application Resume to relaunch the suspended instance Windows Phone Application Lifecycle 3/18/2014 Not running Running LaunchingClosing DeactivatingActivating Dormant
  • 5. Application Lifecycle Events • The Windows Phone application environment notifies an application about lifecycle events through a set of events • In the project templates, the events are already wired up in App.xaml and the event handler methods are in the App.xaml.cs file • Initially the event handler methods are empty // 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) { }
  • 7. Launching and Closing – what we have seen • When a Windows Phone 8 application is started the Application_Launching event handler method is called • Good place to load content from backing store • When a Windows Phone 8 application is ended the Application_Closing event handler method is called • Good place to save content in backing store • The debugger will keep running even when your application is “stopped” • This makes it easier to debug start and stop behaviour • But you need to stop it yourself to work on your code.. 3/18/2014 Not running Running Application_ Launching Application_ Closing
  • 8. Application Deactivation and Reactivation • If you are from a Windows desktop background this behavior will make perfect sense • Windows desktop applications can subscribe to events that are fired when the program starts and ends • However, Windows Phone applications operate on a smartphone and the OS imposes restrictions designed to save battery life and ensure a good end-user experience • At any give time only one applications is in the foreground • Users may deactivate their applications and reactivate them later • Applications have to deal with being activated and deactivated 3/18/20148
  • 10. Dormant applications • The user can make your application dormant at any time • They could launch another program from the start screen or the Programs menu • The Application_Deactivated method is called in this situation • External events may also make your application dormant • If a phone call is received when your program is running it will be made dormant • If the lock screen shows after a period of inactivity • A user may return to your application and resume it at a later time 3/18/2014 Tombstoned Running DeactivatingActivating Dormant
  • 11. Dormant applications • The user can make your application dormant at any time • They could launch another program from the start screen or the Programs menu • The Application_Deactivated method is called in this situation • External events may also make your application dormant • If a phone call is received when your program is running it will be made dormant • If the lock screen shows after a period of inactivity • A user may return to your application and resume it at a later time 3/18/2014 Tombstoned Running DeactivatingActivating Dormant There is no guarantee that your application will ever be resumed if it is made dormant
  • 12. Dealing with Dormant • When your application is made dormant it must do as much data persistence as if it was being closed • Because Application_Deactivated and Application_Closing will mean the same thing if the user never comes back to your program • Your application can run for up to 5 seconds to perform this tidying up • After that it will be forcibly removed from memory • When an application is resumed from dormant it will automatically resume at the page where it was deactivated • This behaviour is managed by the operating system • All objects are still in memory exactly as they were at the moment the app was suspended 3/18/201412
  • 14. Resuming an Application – Fast Application Switching • The user can resume a suspended application by ‘unwinding’ the application history stack by continually pressing the ‘Back’ key to close applications higher up the history stack, until the suspended application is reached • The Back button also has a “long press” behaviour • This allows the user to select the active application from the stack of interrupted ones • Screenshots of all the applications in the stack are displayed and the user can select the one that they want • The application is brought directly into the foreground if it is selected by the user • On Windows Phone 8, the app history stack can hold up to 8 applications 14
  • 15. From Dormant to Tombstoned • An application will be held dormant in memory alongside other applications • If the operating system becomes short of memory it will discard the cached state of the oldest dormant application • This process is called “Tombstoning” • The page navigation history and a special cache called the state dictionaries are maintained for a tombstoned application • When a dormant application is resumed the application resumes running just where it left off • When a tombstoned application is resumed, it restarts at the correct page but all application state has been lost – you must reload it • An application can determine which state it is being activated from 3/18/201415 Tombstoned Running DeactivatingActivating Dormant
  • 17. Resumed from Dormant or Tombstoned? • You can also check a flag to see if a the application is being resumed from dormant or tombstoned state private void Application_Activated(object sender, ActivatedEventArgs e) { if (e.IsApplicationInstancePreserved) { // Dormant - objects in memory intact } else { // Tombstoned - need to reload } }
  • 18. Debugging Tombstoning • You can force an application to be “tombstoned” (removed from memory) when it is made dormant by setting this in Visual Studio • You should do this as part of your testing regime • You can also use the Simulation Dashboard to show the lock screen on the emulator which will also cause your application to be made dormant 3/18/201418
  • 19. Demo 3: Dormant vs Tombstoned
  • 20. States and Tombstones • When an application is resumed from Dormant, it resumes exactly where it left off • All objects and their state is still in memory • You may need to run some logic to reset time-dependent code or networking calls • When an application is resumed from Tombstoned, it resumes on the same page where it left off but all in-memory objects and the state of controls has been lost • Persistent data will have been restored, but what about transient data or “work in progress” at the time the app was suspended? • This is what the state dictionaries are for, to store transient data • State dictionaries are held by the system for suspended applications • When a new instance of an application is launched the state dictionaries are empty • If there is a previous instance of the application that is suspended, standard behaviour is that the suspended instance – along with its state dictionaries - is discarded 3/18/201420
  • 21. The Application State dictionary • Transient data for a tombstoned application may be stored in the application state dictionary • This can be set in the Application_Deactivated method and then restored to memory when the application is activated from tombstoned • This means that the Application_Deactivated method has two things to do: • Store persistent data in case the application is never activated again • Optionally store transient data in the application state dictionary in case the user comes back to the application from a tombstoned state PhoneApplicationService.Current.State["Url"] = "www.robmiles.com";
  • 22. Saving Transient Data on Deactivation • Use the Page State dictionary to store transient data at page scope such as data the user has entered but not saved yet • Page and Application State are string-value dictionaries held in memory by the system but which is not retained over reboots protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back && e.NavigationMode != System.Windows.Navigation.NavigationMode.Forward) { // If we are exiting the page because we've navigated back or forward, // no need to save transient data, because this page is complete. // Otherwise, we're being deactivated, so save transient data // in case we get tombstoned this.State["incompleteEntry"] = this.logTextBox.Text; } }
  • 23. Restoring Transient Data on Reactivation • In OnNavigatedTo, if the State dictionary contains the value stored by OnNavigatedFrom, then you know that the page is displaying because the application is being reactivated protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); // If the State dictionary contains our transient data, // we're being reactivated so restore the transient data if (this.State.ContainsKey("incompleteEntry")) { this.logTextBox.Text = (string)this.State["incompleteEntry"]; } }
  • 24. Demo 4: Using State Dictionaries
  • 25. Running Under Lock Screen on Windows Phone
  • 26. Windows Phone Idle Detection • The Windows Phone operating system will detect when an application is idle • When the phone enters idle state the lock screen is engaged • The user can configure the timeout value, or even turn it off • When an application is determined to be idle it will be Deactivated and then Activated when the user unlocks the phone again • An application disable this behaviour, so that it is able to run underneath the lock screen 3/18/201426
  • 27. Windows Phone Idle Detection • The Windows Phone operating system will detect when an application is idle • When the phone enters idle state the lock screen is engaged • The user can configure the timeout value, or even turn it off • When an application is determined to be idle it will be Deactivated and then Activated when the user unlocks the phone again • An application disable this behaviour, so that it is able to run underneath the lock screen This is strong magic. It gives you the means to create a “battery flattener” which users will hate. Use it with care, read the guidance in the documentation and follow the checklists. 3/18/201427
  • 28. Disabling Idle Detection • This statement disables idle detection mode for your application • It will now continue running under the lock screen • There will be no Activated or Deactivated messages when the phone locks because the application is timed out • Note that your application will still be deactivated if the users presses the Start button • Disabling idle detection is not a way that you can run two applications at once PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
  • 29. Detecting “Obscured” events • Your application can connect to the Obscured event for the enclosing frame • This will fire if something happens (Toast message, Lock Screen, Incoming call) that will obscure your frame • It also fires when the obscuring item is removed • You can use the ObscuredEventArgs value to detect the context of the call App.RootFrame.Obscured += RootFrame_Obscured; ... void RootFrame_Obscured(object sender, ObscuredEventArgs e) { }
  • 30. Simulation Dashboard • The Simulation Dashboard is one of the tools supplied with Visual Studio 2012 • It lets you simulate the environment of your application • It also lets you lock and unlock the screen of the emulator phone • This will cause Deactivated and Activated events to fire in your program 3/18/201430
  • 32. Fast Application Resume • By default a fresh instance of your application is always launched when the user starts a new copy from the programs page or a deep link in a secondary tile or reminder, or via new features such as File and Protocol associations or launching by speech commands • This forces all the classes and data to be reloaded and slows down activation • Windows Phone 8 provides Fast Application Resume, which reactivates a dormant application if the user launches a new copy • This feature was added to enable background location tracking • You can take advantage of it to reactivate a dormant application instead of launching a new instance 3/18/201441
  • 34. Enabling FAR in PropertiesWMAppManifest.xml • This is how FAR is selected • You have to edit the file by hand, there is no GUI for this <Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/> </Tasks> <Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"> <BackgroundExecution> <ExecutionType Name="LocationTracking" /> </BackgroundExecution> </DefaultTask> </Tasks>
  • 35. The Two Flavors of FAR • Oddly, you enable FAR by registering your app as a “LocationTracking” app – whether or not you actually track location! • If you have marked your app LocationTracking *and* you actively track location by using the GeoCoordinateWatcher or GeoLocator classes: • App continues to run in the background if it is deactivated while actively tracking • If re-launched from the Apps menu or via a Deep Link, the existing instance will be reactivated if it is running in the background or fast resumed if it is dormant • More on this in the Maps and Location Session! • If you have marked your app LocationTracking but you don’t have any Geolocation code in your app, then your app is one that can be fast resumed • When deactivated, your app is suspended just like normal • But when your app is relaunched and the previous instance is currently dormant, that previous instance is fast resumed 3/18/201444
  • 36. Standard App Relaunch Behavior ActiveDormant
  • 37. ‘True’ Background Location Tracking Behavior ActiveDormant Location Tracking
  • 39. Sounds Great! So Why Don’t I Use FAR With All My Apps? • You need to be very careful on protecting the user experience with respect to page navigation • Deep Link activation • On non FAR-enabled apps, if you launch an app to ‘Page2’, then ‘Page2’ is the only page in the page backstack, and pressing Back closes the app • For FAR-enabled apps, if you launch an app to ‘Page2’, but there was a suspended instance containing a page history backstack of ‘MainPage’, ‘Page1’, ‘Page2’, ‘Page3’ then the newly launched app will end up with a backstack of ‘MainPage’, ‘Page1’, ‘Page2’, ‘Page3’, ‘Page2’ • What should the user experience be here? 3/18/201448
  • 40. App List/Primary Tile Behavior of FAR-enabled Apps • Similarly, the user expectation when launching an app from an application tile on the Start Screen or from the Apps List is that the app will launch at the home page of the app • This is what will happen for non FAR-enabled apps • This is what will happen even for FAR-enabled apps if there is no suspended instance at the time the app is launched • Since your app can now resume, what should the user experience be? • Should you always launch on the home page to match previous behaviour of Windows Phone apps? • Or should you resume at the page the user was last on? • If you resume at the last page the user was on, think about how the user will navigate to the home page; good idea to put a home icon on the app bar of the page the user lands on 3/18/201449
  • 41. Detecting Resume in a FAR-enabled App • In a true Background Location Tracking app, when the app is sent to the background it continues to run • App will get PhoneApplicationService.RunningInBackground event instead of the Application_Deactivated event • When an app enabled for Fast App Resume (aka FAR) is relaunched from the App List or a Deep Link: • Page on the top of the backstack gets navigated with NavigationMode.Reset • Next, the page in the new launch url will be navigated to with NavigationMode.New • You can decide whether to unload the page backstack or not, or maybe cancel the navigation to the new page 3/18/201450
  • 42. private void InitializePhoneApplication() { ... // Handle reset requests for clearing the backstack RootFrame.Navigated += CheckForResetNavigation; ... } private void CheckForResetNavigation(object sender, NavigationEventArgs e) { // If the app has received a 'reset' navigation, then we need to check // on the next navigation to see if the page stack should be reset if (e.NavigationMode == NavigationMode.Reset) RootFrame.Navigated += ClearBackStackAfterReset; } Clearing Previously Launched Pages on Fast App Resume Add Logic to App.Xaml.cs to Check for Reset Navigation (Behavior Already Implemented in Project Templates) 3/18/2014Microsoft confidential51
  • 43. private void InitializePhoneApplication() { ... // Handle reset requests for clearing the backstack RootFrame.Navigated += CheckForResetNavigation; ... } private void CheckForResetNavigation(object sender, NavigationEventArgs e) { // If the app has received a 'reset' navigation, then we need to check // on the next navigation to see if the page stack should be reset if (e.NavigationMode == NavigationMode.Reset) RootFrame.Navigated += ClearBackStackAfterReset; } private void ClearBackStackAfterReset(object sender, NavigationEventArgs e) Clearing Previously Launched Pages on Fast App Resume Add Logic to App.Xaml.cs to Check for Reset Navigation (Behavior Already Implemented in Project Templates) 3/18/2014Microsoft confidential52
  • 44. Review • Programs can be Launched (from new) or Activated (from Dormant or Tombstoned) • The operating system provides a state storage object and navigates to the correct page when activating an application that has been running, but you have to repopulate forms • Programs can run behind the Lock Screen by disabling Idle Timeout – but this is potentially dangerous (and apps must deal with the Obscured event in this situation) • The system maintains a Back Stack for application navigation. This must be managed to present the best user experience when applications are started in different ways • Applications are normally launched anew each time they are started from the Programs page, but it is now possible to restart a suspended instance using Fast Application Resume • YOU MUST PLAN YOUR LAUNCHING AND BACK STACK BEHAVIOUR FROM THE START 3/18/201453
  • 45. The information herein is for informational purposes only an represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. Š 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.