1 / 45

Fundamentals of Metro style apps: how and when your app will run

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

dick
Download Presentation

Fundamentals of Metro style apps: how and when your app will run

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. APP-409T Fundamentals of Metro style apps: how and when your app will run Ben Srour Senior Program Manager Lead Microsoft Corporation

  2. 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

  3. Changing when apps run User selects app for foreground User launches many apps System manages app lifetime User manages app lifetime

  4. 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

  5. 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!

  6. Termination happens • System needs more memory • User switch occurs • System shutdown • Apps crash Apps do not get notified when they are getting terminated

  7. demo Process lifetime policy

  8. 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

  9. 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 • }

  10. 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

  11. Launching apps

  12. Changing user needs Information snacking Sharing between apps Searching in context

  13. Changing how apps are launched Activate from tile, search, share, etc. App launch from Start

  14. 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

  15. demo App activation with contracts

  16. 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

  17. 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

  18. Tile launch activation Running app activated event User taps on Tile launch eventArgs.kind Splash Screen shown

  19. 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){ • } • }

  20. Tips for making your app look and feel fresh

  21. Polished apps look like they are running even when they are not.

  22. Incrementally save user data • Work is lost • Work is saved • Great apps always save and restore app state

  23. 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

  24. 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

  25. 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

  26. Best practices for saving and restoring state

  27. demo Saving and restoring state

  28. Using live tiles to appear always running

  29. 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

  30. 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

  31. 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

  32. More ways your app can run

  33. 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

  34. 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

  35. 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)

  36. Recap

  37. 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

  38. 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

  39. 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

  40. 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

  41. 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

  42. Further reading and documentation • SDK Samples • Activation and Lifetime • Splash Screens • Tiles and Notifications • Share • Search

  43. thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback

  44. © 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.

More Related