windows 8 devunleashed - session 3

43
Session III – Lifecycle and More Daryl Rudolph

Upload: drudolph11

Post on 21-Nov-2014

326 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Windows 8 DevUnleashed - Session 3

Session III – Lifecycle and More

Daryl Rudolph

Page 2: Windows 8 DevUnleashed - Session 3

Agenda

ApplicationLifecycle

Live Tiles, Background Process andLock Screen

Implementing the Search Contract

Page 3: Windows 8 DevUnleashed - Session 3

Application Lifecycle

Show the flow

Feel Connected and Alive

Page 4: Windows 8 DevUnleashed - Session 3

Memory Management

User selects app for foreground

System manages app lifetime

User launches many apps

User manages app lifetime

Page 5: Windows 8 DevUnleashed - Session 3

App process lifetime

RunningApp

SuspendedApp

Suspending Terminated

AppLow

MemoryResumin

g

Page 6: Windows 8 DevUnleashed - Session 3

Application States

Running

SuspendedNot Running

Resuming

Activated Suspending

Page 7: Windows 8 DevUnleashed - Session 3

Process lifetime walkthrough

App 1 App 2 App 3Running

Suspended

Terminated

… App N

Apps suspend after a short

delay

App terminated under memory

pressure without notification

Apps resume instantly from

suspend

Page 8: Windows 8 DevUnleashed - Session 3

When do apps get terminated

• System needs more memory• User switch occurs• System shutdown• Apps crash

Apps do not get notified when they are getting

terminated

Page 9: Windows 8 DevUnleashed - Session 3

Process state transitions

Running

App

SuspendedApp

suspendingTermina

tedApp

Low Memory

Code gets to runNo

code runs

App not running

resuming

App gets 5seconds to

handle suspend

App is not notified before

termination

Apps are notified when they have been resumed

User Launches App

Splash screen

Page 10: Windows 8 DevUnleashed - Session 3

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

Page 11: Windows 8 DevUnleashed - Session 3

Interacting with your users

Entice Discover Share

Page 12: Windows 8 DevUnleashed - Session 3

App Activation Through Contracts

• Apps are activated through contracts• Launch, search, ShareTarget, etc.

• Apps need to initialize contract specific actions

• Context is provided

Running App

launch

shareTarget

activated

kind

search

Page 13: Windows 8 DevUnleashed - Session 3

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

Page 14: Windows 8 DevUnleashed - Session 3

Best practices for saving and restoring state

Scenario You should….User is using your App

• Save user data incrementally

App switched away from (Suspending)

• Save where the user is – what screen they are on, for example

Not running App launched by user (Activated)

• Bring the user back and restore their session as if they never left

Suspended App launched by user (Resuming)

• Do nothing

Page 15: Windows 8 DevUnleashed - Session 3

Demo

Suspend Demo

Page 16: Windows 8 DevUnleashed - Session 3

Search Contract

Finding your application

Use the Right Contracts

Page 17: Windows 8 DevUnleashed - Session 3

Search 1 2 3

1. Search box is scoped to the main app on screen

2. Query suggestions provided by the main app on screen• Autocompletes to terms for

which the app has search results

3. List of installed Windows 8 style apps that have implemented the search contract

2

3

1

Page 18: Windows 8 DevUnleashed - Session 3

Query submitted

User

Show Search results view

Yes

Show previous

search results view

NoQuery chang

ed?

User enters a query and hits

Search

User selects a query

suggestion

Search Pane

Submit query to App

Search App

Query Submitted

Event

Page 19: Windows 8 DevUnleashed - Session 3

Demo

Search Contract Demo

Page 20: Windows 8 DevUnleashed - Session 3

Live tiles

Keep the action going

Invest in a Great Tile

Page 21: Windows 8 DevUnleashed - Session 3
Page 22: Windows 8 DevUnleashed - Session 3

Tiles Sizes• Tap on tile to launch or switch to an

app

• Static default tile specified in app manifest

• Two sizes:

Both sizes can have live updates

Wide (2x1)

310X150

Square (1x1)

150X150

Page 23: Windows 8 DevUnleashed - Session 3

Badges

• Overlays status on top of tile• Supports square and wide tiles• Number up to 99 or pre-defined glyph:

• Always legible on top of images

BadgeBadge

Page 24: Windows 8 DevUnleashed - Session 3

Notification Queuing

• By default only last notification shown• Opt-in to automatically cycle tile through last five

notifications

Page 25: Windows 8 DevUnleashed - Session 3

Live Tiles things to remember

• Tiles updated using pre-defined templates

• Text-only, image-only or combination• JPEG or PNG only, max size 150 KB• Local, cloud or background updates

Invest in a Great Tile

Page 26: Windows 8 DevUnleashed - Session 3

Demo

Live Tiles

Page 27: Windows 8 DevUnleashed - Session 3

Secondary Tiles

• Tiles created by “pinning” content from app

• Pin initiated by app via simple runtime call

• User confirms pin operation via system UI

• Exposes a personalized surface for app

• Same capabilities as app tiles• Launch leads to relevant content

Page 28: Windows 8 DevUnleashed - Session 3

Demo

Secondary Tiles

Page 29: Windows 8 DevUnleashed - Session 3

RTC – Real Time Communication apps

Keep the action going

Invest in a Great Tile

Page 30: Windows 8 DevUnleashed - Session 3

Review app process lifetime

RunningApp

SuspendedApp

Suspending Terminated

AppLow

MemoryResumin

g

Page 31: Windows 8 DevUnleashed - Session 3

…with RTC apps

RunningApp

SuspendedApp

Suspending Terminated

AppLow

MemoryResumin

g

BackgroundTask

Executes

The app lifecycle

BackgroundTask

Executes

BackgroundTask

Executes

Page 32: Windows 8 DevUnleashed - Session 3

Network Trigger

RTC trigger APIs

System Trigger Time Trigger

Background Task Infrastructure

VoIP IM Your App

App

OS

Page 33: Windows 8 DevUnleashed - Session 3

Network Trigger

System Trigger

Time Trigger

Background Task Infrastructure

VoIP IM Mail

Changing Live Tile

Time Trigger

Setting up a Time Trigger

Page 34: Windows 8 DevUnleashed - Session 3

Live tiles with push notifications

• 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

App Cloud Service

Windows Push Notification Service

(WNS)

HTTP POST

Notification Delivered

Page 35: Windows 8 DevUnleashed - Session 3

Push Notification Overview

1. Request Channel URI

2. Register with your Cloud Service

3. Authenticate & Push Notification

Windows 8

Notification

Client Platform

Windows 8 Style

App

App Service

Windows Push Notification

Service

1

2

3

3

POST <channel URI> HTTP/1.1Content-Type: text/xmlHost: db3.notify.windows.comX-WNS-Type: wns/badgeAuthorization: Bearer <authentication token>Content-Length: 58

<?xml version="1.0" encoding="utf-8"?><badge value="11"/>

Page 36: Windows 8 DevUnleashed - Session 3

Register for Time TriggerTime Trigger

using Windows.ApplicationModel.Background;

// Specify the triggerTimeTrigger trigger = new TimeTrigger(UpdateInterval, Periodic);

Create time

trigger

// Associate app code with the triggerBackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();taskBuilder.TaskEntryPoint = “MyApp.Background.UpdateEmailTask";taskBuilder.SetTrigger(trigger);taskBuilder.Name = “TimerExpiry";

Associate trigger

with app code

// Register the task for background executionIBackgroundTaskRegistration taskRegistration = taskBuilder.Register();

Register trigger

Page 37: Windows 8 DevUnleashed - Session 3

public sealed class UpdateLiveTileTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) {

// Your app code to update email }}}

using Windows.ApplicationModel.Background;

Time Trigger App execution upon

timer expiry

Page 38: Windows 8 DevUnleashed - Session 3

Demo

Live Tiles /Lock Screen/Background

Page 39: Windows 8 DevUnleashed - Session 3

Best Practices for Tiles

• Display new, tailored and engaging content to the user

• Keep tile fresh by updating as your app content changes

• Reference content that lives on your app’s home page so the user can find it easily.

• Keep content safely ignorable and glanceable - for short messages only

• Use square size if tile is not live• No display ads!

Page 40: Windows 8 DevUnleashed - Session 3

Agenda

ApplicationLifecycle

Live Tiles, Background Process andLock Screen

Implementing the Search Contract

Page 41: Windows 8 DevUnleashed - Session 3

Hands-On Lab 3 OR Create your own app

Running in the background

Page 42: Windows 8 DevUnleashed - Session 3

Create your own app

• You can work on Hands-on Lab 3 OR Create your own app• You have until 4:20 PM• Don’t have to decide if you are entering until 4:20 PM• Presentation can be PowerPoint and/or demonstration

• Must let me know beforehand if you don’t have VGA connection

• Each contestant will have exactly 3 minutes to present!• Be creative. Keep in mind the traits of a great Windows 8

app!

• Note: Anyone who attended today can enter to win the app contest sponsored by Component Art for a $10,000 grand prize, even if you don’t enter today’s contest.

Page 43: Windows 8 DevUnleashed - Session 3

Contact/References

• Magenic – http://www.magenic.com• Daryl Rudolph – [email protected]

• http://dev.windows.com

• http://design.windows.com

• API Sites• http://www.restfulwebservices.net• http://developer.mashery.com/apis• http://www.programmableweb.com