450 likes | 844 Views
APP-409T. Fundamentals of Metro style apps: how and when your app will run. Ben Srour Senior Program Manager Lead Microsoft Corporation. Agenda. Learn when a pps r un Learn how apps can run Tips for making a pps a lways l ook l ike t hey a re r unning
E N D
APP-409T Fundamentals of Metro style apps: how and when your app will run Ben Srour Senior Program Manager Lead Microsoft Corporation
Agenda • Learn when apps run • Learn how apps can run • Tips for making apps always look like they are running • By saving and restoring state • Using live tiles • Discuss more ways apps can run You’ll leave with an understanding of • How and when your Metro style app will run on Windows 8 • How to interact with the system to keep your app fresh
Changing when apps run User selects app for foreground User launches many apps System manages app lifetime User manages app lifetime
Process lifetime walkthrough App 1 App 2 App N App 3 Running … Apps suspend after a short delay Apps resume instantly from suspend Suspended App terminated under memory pressure without notification Terminated
Introducing suspend • System resources focused on app user is interacting with in the foreground • Inactive apps have no impact on battery life or responsiveness, they are suspended by the OS • Enables instant switching between apps!
Termination happens • System needs more memory • User switch occurs • System shutdown • Apps crash Apps do not get notified when they are getting terminated
demo Process lifetime policy
Process state transitions App gets 5s to handle suspend App is not notified before termination suspending Running App Suspended App Terminated App User Launches App Low Memory resuming Apps are notified when they have been resumed Splash screen Code gets to run No code runs App not running
Registering for suspend and resume is easy • //Register for the Suspending event and call suspendingHandler when received • Windows.UI.WebUI.WebUIApplication.addEventListener("suspending",suspendingHandler); • //Handle the suspending event and save the current user session using WinJSsessionState • functionsuspendingHandler(eventArgs){ • //We are getting suspended • } • //Register for the Resuming event and call resumingHandler when received • Windows.UI.WebUI.WebUIApplication.addEventListener("resuming",resumingHandler); • functionresumingHandler(){ • //We are getting resumed, in general do nothing • }
Suspend under the hood • Suspended apps are not scheduled by the NT Kernel • No CPU, Disk or Network consumed • All threads are suspended • Apps remain in memory • Kernel ensures apps are not suspended in critical sections that could cause system wide deadlocks • Apps instantly resumed from suspend when brought to foreground
Changing user needs Information snacking Sharing between apps Searching in context
Changing how apps are launched Activate from tile, search, share, etc. App launch from Start
App Activation Through Contracts • Apps are activated through contracts • Launch, search, ShareTarget, etc. • Apps need to initialize contract specific actions • Context is provided kind Running App launch activated shareTarget search
demo App activation with contracts
Splash Screens during activation • System provided Splash Screen mechanism provides consistent transition to your app • Shown while Windows launches your app • Presented during activation • Developer provides color and image in app manifest • Apps need to present a window within 15 seconds of activation or the app will be terminated
Extended Splash Screens • Some apps need longer to load • Make your first view of your app the same as the Splash Screen • Splash Screen API can be used to render a Splash Screen manually • See the Splash Screen SDK Sample
Tile launch activation Running app activated event User taps on Tile launch eventArgs.kind Splash Screen shown
Activation • Windows.UI.WebUI.WebUIApplication.addEventListener("activated",activatedHandler); • functionactivatedHandler(eventArgs){ • //Tile Activation initialization logic here • if(eventArgs.kind==Windows.ApplicationModel.Activation.ActivationKind.launch){ • } • //Share Activation initialization logic here • elseif(eventArgs.kind==Windows.ApplicationModel.Activation.ActivationKind.shareTarget){ • } • }
Polished apps look like they are running even when they are not.
Incrementally save user data • Work is lost • Work is saved • Great apps always save and restore app state
Saving app data • Save app data incrementally while app is getting used • app data • Custom data structures that are specific to your app • Windows.Storage.ApplicationData • Use file I/O if necessary
Saving/restoring user session state • Only save and restore user session metadata • Where the user is in an app • HTML/JS • Use WinJS.Application.sessionState object • Property bag that automatically serializes to disk during suspend • Reloads property bag from disk on activation • Smart about not reloading state if app crashed • XAML and C++ • SuspensionManager class available in SDK samples does the same as sessionState in HTML/JS
App crash? Start over • Apps that are stuck are no fun • Your app can be terminated abruptly in any of these cases • Too long to load • Too long to suspend • Stopped handling input messages (Blocking I/O on UI thread) • Task manager • Bring the user back home, and ignore saved user session state • previousExecutionState is provided in activation event args
demo Saving and restoring state
Use live tiles to appear running • Your app’s tile is an opportunity to provide value to users even when they are not using your app • Gives the user the sense that there is something going on with your app, and is an invitation to go back • Two mechanisms available to update tiles on the Start screen
Updating tiles locally • Use local notifications while your app is running to update your tile • Great for reflecting the state of the app • Downloaded pictures • Current page in a book Running App Call Local Notification API
Live tiles with push notifications App Cloud Service • Tiles can be updated even if your app is not running! • Push notifications can be used to remotely update a tile on the Start screen • Great for showing the newest content available to your users • For more: [396] Using tiles and notifications HTTP POST Windows Push Notification Service (WNS) Notification Delivered
More ways your app can run
Background audio playback • Apps can play audio in the background • Developers must specify background audio in the app manifest • Each audio stream is given a type (communication, media, game) • Only one audio stream type may play at a given time • For more: [778] Media fundamentals of a communications app
Upload/download in the background • Use the BackgroundTransferAPI to upload or download data over HTTP in the background • Initiate upload/download from the foreground and it can continue even though your app is suspended • For more: [581] Making apps social and connected with HTTP services
Lock screen apps • Apps that can run in the background • Designed for real-time communications apps (Mail, IM, VoIP) • Maintain TCP sockets in the background • Run code periodically • Run code in response to system events (user login)
Activation best practices • Activate quickly! • Initialize your app • Delay activities you can until needed • Pickup where the user left off • Show an extended splash screen if you need more than 15s
Suspend best practices • Save state quickly – you have 5 seconds • Assume you will be terminated – save user session data • Update your app’s tile • Release exclusive access to shared resources (files, devices, network etc.) • Save app data incrementally before suspend
Review • Windows’ new philosophy on how and when your app will run • Apps are suspended, and eventually terminated, in the background • Keep your app alive and fresh by • Saving and restoring state • Using live tiles
Related sessions • [APP-162T] Building high performance Metro style apps using HTML5 • [APP-737T] Metro style apps using XAML: what you need to know • [PLAT-475T] Create experiences that span devices • [APP-396T] Using tiles and notifications • [SAC-963H] SMB2 in a continuously available file server • [PLAT-581T] Making apps social and connected with HTTP services • [APP-405T] Share: your app powers the Windows 8 share experience • [APP-406T] Search: integrating into the Windows 8 search experience • [PLAT-778T] Media fundamentals of a communications app • [APP-410T] Real time communication: keep your Metro style app connected whether it is running or suspended
Links • App Lifecycle • How to activate an app • How to suspend an app • How to resume an app • The “WNS and Live Connect Application Management Site” will get you started using push notifications • https://manage.dev.live.com/build • Introduction to Background Tasks
Further reading and documentation • SDK Samples • Activation and Lifetime • Splash Screens • Tiles and Notifications • Share • Search
thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback
© 2011 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. 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.