Windows Runtime App Lifecycle

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Payroll and HR Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Interactivity Navigating a data model Working with large quantities of data Entry Editing and adding data User feedback and validation Presentation.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
30 April 2014 Building Apps for Windows Phone 8.1 Jump Start WinRT Apps & Silverlight.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
WinRT Apps 29 April 2014 Building Apps for Windows Phone 8.1 Jump Start.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Connect with life Connect with life
A Windows Azure application runs multiple instances of each role A Windows Azure application behaves correctly when.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Developer's guide to Windows 10 Insider Preview Andy & Jerry
Feature: Suggested Item Enhancements – Sales Script and Additional Information © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
Feature: Void Historical/Open Transaction Updates © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

IoCompleteRequest (Irp);... p = NULL; …f(p);
TechEd /26/2018 3:42 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Windows Phone Platform Integration Yochay Kiriaty
Microsoft Dynamics NAV 2018 – what’s new
Возможности Excel 2010, о которых следует знать
Microsoft Build /9/2018 8:05 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Windows Phone multitasking
11/19/ | App Model & Storage © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Title of Presentation 11/22/2018 3:34 PM
Metro style apps using XAML: Make your app shine
Office Mac /30/2018 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
12/2/ :23 PM APP-410T Real time communication: keep your Metro style app connected whether it is running or suspended Raghu Gatta Principal Development.
Title of Presentation 12/2/2018 3:48 PM
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
4/27/17, Bell #8 What amount of net pay has been earned this period?
Windows 8 Security Internals
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
WCL425 App Compat for Nerds Chris Jackson.
Presentation transcript:

Windows Runtime App Lifecycle WinRT Apps Building Apps for Windows Phone 8.1 Jump Start Building Windows Runtime Apps using C# and XAML Windows Runtime App Lifecycle

In this module… Windows Runtime App Lifecycle Launch Suspend Resume Termination Saving and Restoring State

Lifecycle? phone resources are scarce (battery especially) OS runs one foreground app at a time other apps are suspended and/or terminated OS has many mechanisms for an app to appear ‘alive’ OS has controlled mechanisms for background code

Lifecycle? lifecycle is very similar to Windows 8.1 app lifecycle differences due to the nature of Phone hardware and the need to maintain compatibility with WP8.0, WP7.x apps different from Windows Phone 8.0 app lifecycle concepts will be familiar to any mobile app developer

launch, suspend, resume

User launches app Launch Running NotRunning

Application.OnLaunched override sealed partial class App : Application { /// <summary> /// Invoked when the application is launched normally by the end user. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) // How did the app exit the last time it was run (if at all) ApplicationExecutionState previousState = e.PreviousExecutionState; // What kind of launch is this? ActivationKind activationKind = e.Kind; // ... NotRunning Running Suspended Terminated ClosedByUser Launch File Protocol VoiceCommand Etc.

User navigates away from your app App is suspended All code stopped No timers tick No events fire Process still alive and in memory Code has a chance to respond (next slide) Leaves App

Application.Suspending event This code has limited time to run. Doing the minimum amount of work here will improve the user’s experience of your app. NB: Only ask for a deferral if you are doing async work. A deferral does not give you any more time to suspend. sealed partial class App : Application { public App() this.InitializeComponent(); this.Suspending += OnSuspending; } private async void OnSuspending(object sender, SuspendingEventArgs e) // Ask for a deferral if you need to do async work var deferral = e.SuspendingOperation.GetDeferral(); // TODO: whatever async work you need to do when suspending deferral.Complete(); // Then mark the deferral complete

User returns to your app Same app is resumed Same process, same memory so values of variables are intact All code runs Code has a chance to respond... Back Launch Switcher

Application.Resuming event 12/31/2018 Application.Resuming event sealed partial class App : Application { public App() this.InitializeComponent(); this.Suspending += OnSuspending; this.Resuming += OnResuming; } private void OnResuming(object sender, object e) // TODO: whatever you need to do to resume your app © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

The debugger is/isn’t your friend  By design - your code will not suspend/resume under the debugger  The debugger has a specific feature to simulate suspend/resume 

What to do on resuming? Check external data or conditions that might change while the app was suspended Possibly factoring in the time elapsed between suspension and resumption Examples (taken from http://bit.ly/w8Resuming): refresh data from an online source refresh the app’s view of connectivity – online or offline? refresh sensor data such as compass, geolocation retry a networking call that may have failed while suspended refresh layout – device may have reorientated since suspension check for new data populated by background tasks or system roaming

Apps can be closed by the user ClosedByUser Running NB: Back button does not close the app

Demo

Termination

The OS can terminate your app System has a priority system for determining which app to terminate. User Runs Another App OS Short of Memory OS Terminates An App Terminated

The OS can terminate your app OS does not wake an app to terminate it – no notification App is removed from task switcher list

User ‘returns’ to a terminated app User will be unaware that the app was terminated Would often expect that their experience simply continues The developers’ job is to maintain the illusion that the app has always been running, even though it hasn’t

User ‘returns’ to a terminated app User must not lose data & should continue recent activity seamlessly App may need to restore transient session state Includes page navigation history, page position/parameters & contents of input fields Every app defines ‘recent’ differently

Transient data versus persistent data 12:38 Work Tel: 0111 222 333 Home Tel: 0444 555 666 Email jim@jones.com CONTACTS Jim Jones 12:38 CONTACTS Add Phone Mobile Phone Phone type Phone number 0888 777 App Data Local Folder (or roaming folder for Data) 12:38 CONTACTS all Data 12:38 Jim Jones Tel: 0111 222 333 Bob Brown Tel: 0444 555 666 Arthur Abbott Tel: 0777 888 999 State Navigate(Page2, ID param) Navigate(Page3, ID param)

Demo

Help from the framework & templates The Frame class has [Get/Set]NavigationState method to (re)store navigation history as a String The SuspensionManager class helps with (re)storing global & Frame state in a file The NavigationHelper class wires the Page to the SuspensionManager via easy page-level events the last 2 classes are not in the blank template, you need to add “basic page” items or use another template to get them

For a clean, new launch of the app... 12/31/2018 For a clean, new launch of the app... OnLaunched App Frame Suspension Manager RegisterFrame() allows suspension manager to; get/set navigation history be aware as the Frame is navigating © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Only if the app was previously terminated 12/31/2018 Only if the app was previously terminated OnLaunched App Suspension Manager RestoreAsync() © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

this history is tracked by the Frame. parameters must be serializable. 12/31/2018 as the app navigates state dictionaries owned by SuspensionManager. entries must be serializable Page A Navigation Helper LoadState( Parameter, null /* dictionary */ ); Navigate(PageA, Parameter) this history is tracked by the Frame. parameters must be serializable. © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12/31/2018 save all state necessary to reconstruct as page may not be cached and/or app may be terminated before page is revisited. as the app navigates Page A Page B Navigation Helper LoadState( Parameter, null /*dictionary*/ ); Navigate(PageB, Parameter) SaveState( dictionary ); Navigation Helper © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12/31/2018 page may be a new or a cached instance. depends on cache mode & memory. as the app navigates Page A Navigation Helper Page B GoBack() LoadState( parameter, dictionary ); SaveState( dictionary ); Navigation Helper © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

as the app navigates null dictionary? - reset controls to defaults. 12/31/2018 as the app navigates null dictionary? - reset controls to defaults. non null dictionary? – restore control state. Page A Page B Navigation Helper LoadState( Parameter, dictionary ); GoForward() SaveState( dictionary ); Navigation Helper © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

as the app suspends ... Suspending App Suspension Manager SaveAsync() 12/31/2018 as the app suspends Suspending App Suspension Manager SaveAsync() State Dictionaries Global Frame 1 Page 1 ... © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

‘Recent’ state with SuspensionManager On startup, you might want a previously terminated app to discard state and start afresh (example: state is not “recent” enough) Can modify SuspensionManager to add this capability

Demo

Related topics Notification mechanisms 12/31/2018 Related topics Notification mechanisms Session 10: Tiles, badges, Toasts and Action Center Additional activation scenarios – e.g. protocol activation Session 14: Sharing Files and Data Background working Session 11: Background Tasks Application Lifecycle in Silverlight Apps Building Apps for Windows Phone 8 Jump Start - Session 5: Windows Phone 8 Application Lifecycle http://aka.ms/Tsatr4 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and 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. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.