31
Multitasking and Triggered Background Processing in Windows Phone 8.1 Rob Irving Senior Software Engineer – ALK Technologies Microsoft MVP – Windows Platform Development www.robwirving.com @ robwirving

Multitasking and Triggered Background Processing in Windows Phone 8.1

Embed Size (px)

Citation preview

Page 1: Multitasking and Triggered Background Processing in Windows Phone 8.1

Multitasking and Triggered Background Processing in Windows Phone 8.1

Rob IrvingSenior Software Engineer – ALK TechnologiesMicrosoft MVP – Windows Platform Developmentwww.robwirving.com@robwirving

Page 2: Multitasking and Triggered Background Processing in Windows Phone 8.1

Rob Irving• Senior Software Engineer at ALK Technologies• Microsoft MVP – Windows Platform Development• Led development effort to bring CoPilot GPS

navigation app to Windows Phone 8• In top 10 Free Navigation Apps in Window Phone store

• Windows Phone Dev by day and night• Released 7 of my own apps to Windows Phone store• http://bit.ly/AppsByRWI

• Blog: www.robwirving.com• Twitter: @robwirving

Page 3: Multitasking and Triggered Background Processing in Windows Phone 8.1

Agenda

• What are Background Tasks• History on Windows Phone 8• What’s new in Windows Phone 8.1• Triggered Background Tasks• Geofencing• XAML Tile Rendering

Page 4: Multitasking and Triggered Background Processing in Windows Phone 8.1

Multi-whosit?Triggered-what-the?

Page 5: Multitasking and Triggered Background Processing in Windows Phone 8.1

Where did we come from?

Page 6: Multitasking and Triggered Background Processing in Windows Phone 8.1

Apps not on screen are suspended

However apps can provide real-time content even when suspended

1. Live tiles or toasts2. Scheduled toasts and notifications 3. OS brokered tasks4. Background tasks and agents

Windows Phone multitasking model

Page 7: Multitasking and Triggered Background Processing in Windows Phone 8.1

Scheduled Task

PeriodicTask, ResourceIntensiveTask

Background Transfer Service

Background Location Tracking

VOIP and Audio Agents

Background Execution in WP8

Page 8: Multitasking and Triggered Background Processing in Windows Phone 8.1

Where are we going?

Page 9: Multitasking and Triggered Background Processing in Windows Phone 8.1

Centered around BackgroundTasks

Hosted in a separate process

Responds to Triggers and Conditions

One trigger per task, multiple conditions

Applications must request access to run in the background

Background Execution in WinRT

Page 10: Multitasking and Triggered Background Processing in Windows Phone 8.1

Basic TriggersTrigger Usage

System TriggerUserPresent , UserAway, SessionConnected, TimeZoneChange, NetworkStateChange, InternetAvailable, ServicingComplete

Run code on system events

TimeTrigger Data synchronization

MaintenanceTrigger Perform maintenance work on AC power

Page 11: Multitasking and Triggered Background Processing in Windows Phone 8.1

Background Tasks in Windows Store ApplicationsDEMO

Page 12: Multitasking and Triggered Background Processing in Windows Phone 8.1

What’s new?

Page 13: Multitasking and Triggered Background Processing in Windows Phone 8.1

Native Background Task functionality is available from Silverlight 8.1 applications

Background Agents are hosted on top of WinRT Background infrastructure

Windows Phone Silverlight 8.1 Apps

Page 14: Multitasking and Triggered Background Processing in Windows Phone 8.1

Bluetooth LE, RFComm and Sensors while not in foreground

Based on existing and new WinRT Bluetooth APIs

New Triggers:GattCharacteristicNotificationTriggerDeviceChangeTriggerDeviceUpdateTriggerRfcommConnectionTrigger

Bluetooth and Sensors

Page 15: Multitasking and Triggered Background Processing in Windows Phone 8.1

Associate a Background Task with WNS channel

RAW push notifications directly activate the Task

Push Triggers

Page 16: Multitasking and Triggered Background Processing in Windows Phone 8.1

Enables contextual or automatic experiences Used to start actions based on location

based notifications Delight the user with relevant proposals,

reminders, data… Get things done behalf of the user

automatically

What is a geofence and why use it

Geofence:virtual perimeter around a place of interest to an app/user

Page 17: Multitasking and Triggered Background Processing in Windows Phone 8.1

Geofence notifications can be received in the background by a background taskAdd a GeofenceGeocircle circle = new Geocircle(circleCenter, radius: 25.5);

Geofence geofence = new Geofence("LincolnSquareStore", circle);

GeofenceMonitor.Current.Geofences.Add(geofence);

Register a background TaskBackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence));

Geofencing

Page 18: Multitasking and Triggered Background Processing in Windows Phone 8.1

Geofences have intuitive, easy-to-use properties.

Circular geofences are supported in this release.

A geofence consists ofProperty Required/optional Values Default

Id Required String N/A

Geoshape RequiredGeocircle (BasicGeoposition + Radius)

N/A

MonitoredStates Optional Entered/Exited/Removed Entered/Exited

SingleUse Optional True/False False

DwellTime Optional Timespan 10s

StartTime Optional DateTimeOffset 0/epoch

Duration Optional Timespan 0/forever

Page 19: Multitasking and Triggered Background Processing in Windows Phone 8.1

GeofencingDEMO

Page 20: Multitasking and Triggered Background Processing in Windows Phone 8.1

Render a Tile from your BackgroundTask!

New class XamlRenderingBackgroundTask BackgroundTask + XAML Visual Tree

Use RenderTargetBitmap to render XAML visual tree

XAML Rendering in BackgroundTask

Page 21: Multitasking and Triggered Background Processing in Windows Phone 8.1

XAML Rendering in BackgroundTaskDEMO

Page 22: Multitasking and Triggered Background Processing in Windows Phone 8.1

Windows.Networking.BackgroundTransfer

No file size restriction

Support for multi-part mime (for large transfers)

Additional verbs (PUT, RETR, STOR) and also FTP

In-progress stream access

Data-Sense and Battery Saver aware

BackgroundTransfer

Page 23: Multitasking and Triggered Background Processing in Windows Phone 8.1

What’s different?

Page 24: Multitasking and Triggered Background Processing in Windows Phone 8.1

OnlineIdConnectedStateChange

LockScreenApplicationAdded

LockScreenApplicationRemoved

ControlChannelTrigger

Not available on Windows Phone

Page 25: Multitasking and Triggered Background Processing in Windows Phone 8.1

Continuous Background Location

Runs-Under-Lock

VoIP Agents

Wallet Agents

Not available for Windows XAML applications

Page 26: Multitasking and Triggered Background Processing in Windows Phone 8.1

Battery Saver andResource Management

Page 27: Multitasking and Triggered Background Processing in Windows Phone 8.1

New in Windows Phone 8.1

Sort and manage which apps can execute in the background

Controls number of apps that can run in the background

Battery Saver

Page 28: Multitasking and Triggered Background Processing in Windows Phone 8.1

All background tasks have CPU, memory and network quotas

Quotas are based on actual CPU usage instead of wall clock time limits only

Wall-clock CPU quota will also be enforced (at least 30 secs)

Memory quota scales based on device capabilitiesTimeTrigger will have a 30 min floor on Phone

Call RequestAccessAsync() to get your full quota!

Resource constraints

Page 29: Multitasking and Triggered Background Processing in Windows Phone 8.1

Memory Constraints

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh977056.aspx#WP_EXTRA_RESOURCE_CONSTRAINTS

Page 30: Multitasking and Triggered Background Processing in Windows Phone 8.1

Build 2014 Sessions channel9.msdn.com/Events/Build/2014

Additional Resources