what's new in windows phone mango for developers

62
Highlights of What’s New in Windows Phone Mango Glen Gordon Developer Evangelist, Microsoft http://glengordon.name

Upload: glen-gordon

Post on 18-Jan-2015

1.515 views

Category:

Technology


7 download

DESCRIPTION

 

TRANSCRIPT

Page 1: What's new in Windows Phone Mango for Developers

Highlights of What’s New in Windows Phone Mango

Glen GordonDeveloper Evangelist, Microsofthttp://glengordon.name

Page 2: What's new in Windows Phone Mango for Developers

Windows Phone

Topics

Fast Application Switching Background Agents Live Tiles XNA/Silverlight integration

Page 3: What's new in Windows Phone Mango for Developers

Demo

Demo 1: Fast Application Switching

Page 4: What's new in Windows Phone Mango for Developers

Windows Phone

Application Lifecycle - Dormant

running

deactivated

dormant

activated

Phone resources detachedThreads & timers suspended

Fast App Resume

Save State!State preserved!e.IsApplicationInstancePreserved== true

Page 5: What's new in Windows Phone Mango for Developers

Windows Phone

Application Lifecycle - Tombstoned

running

deactivated

dormant Phone resources detachedThreads & timers suspended

Restore state!e.IsApplicationInstancePreserved

== false

Resuming .. .

Tombstone the oldest app

Tombstoned

activated

Page 6: What's new in Windows Phone Mango for Developers

Windows Phone

Methods & Events

6

Page 7: What's new in Windows Phone Mango for Developers

Windows Phone

Finding the Resume type

The Activation handler can test a flag to determine the type of resume taking place

private void Application_Activated(object sender, ActivatedEventArgs e){ if (e.IsApplicationInstancePreserved) { // Dormant - objects in memory intact } else { // Tombstoned - need to reload }}

Page 8: What's new in Windows Phone Mango for Developers

Windows Phone

Deactivation Resource ManagementDeactivated App

PhoneApplicationPage.OnNavigatedFrom

PhoneApplicationService.Deactivated

Framework:Detach Resources

Framework:Suspend Timers and Threads

Dormant App

MediaPlayer.PauseMediaElement.Pause

SoundEffectInstance.PauseVibrateController.StopPhotoCamera.Dispose

Save page/global state

XNA Audio Paused

Sensors Notifications suppressed

Networking Cancelled

Sockets Disconnected

MediaElement Disconnected

Camera Disposed

Page 9: What's new in Windows Phone Mango for Developers

Windows Phone

Activation Resource Management

MediaElement.Source/Position/PlaySocket.ConnectAsyncnew PhotoCamera/VideoCamera

Restore app state if tombstoned

Running App

PhoneApplicationPage.OnNavigatedTo

PhoneApplicationService.Activated

Framework:Attach Resources

Framework:Resume Timers and Threads

Dormant App

XNA Audio Resumed

Sensors Notifications resumed

Networking Completed with Cancellation

Sockets -

MediaElement -

Camera -

Page 10: What's new in Windows Phone Mango for Developers

Windows Phone 10

Isolated Storage vs State Storage

Isolated storage is so called because the data for an application is isolated from all other applications

It can be used as filestore where an application can store folders and files

It is slow to access, since it is based on NVRAM technology It can also be used to store name/value pairs, e.g. program

settings State storage is so called because it is used to hold the state of an

application It can be used to store name/value pairs which are held in

memory for dormant or tombstoned applications It provides very quick access to data

Page 11: What's new in Windows Phone Mango for Developers

Demo• With No Storage• With Storage• Fully Working

Captain’s Log

Page 12: What's new in Windows Phone Mango for Developers

Background Tasks

Page 13: What's new in Windows Phone Mango for Developers

Windows Phone 14

Multitasking Capabilities

Background Agents Periodic Resource Intensive

Background Transfer Service Alarms and Reminders Background Audio

Page 14: What's new in Windows Phone Mango for Developers

Windows Phone

Background Agents Agents

Periodic Resource Intensive

An app may have up to one of each Initialized in foreground, run in background

Persisted across reboots User control through Settings

System maximum of 18 periodic agent Agent runs for up to 14 days (can be renewed)

15

Page 15: What's new in Windows Phone Mango for Developers

16

Generic Agent TypesPeriodic Agents Occurrence

Every 30 min Duration

~15 seconds Constraints

<= 6 MB Memory <=10% CPU

Resource Intensive Agents Occurrence

External power Non-cell network

Duration 10 minutes

Constraints <= 6 MB Memory

Page 16: What's new in Windows Phone Mango for Developers

Windows Phone

Background Agent Functionality

17

Allowed Tiles Toast Location Network R/W ISO store Sockets Most framework APIs

Restricted

Display UI XNA libraries Microphone and Camera Sensors Play audio

(may only use background audio APIs)

Page 17: What's new in Windows Phone Mango for Developers

Demo

Demo1: Captain’s Location Log

Page 18: What's new in Windows Phone Mango for Developers

Windows Phone 19

Debugging a Background Task

It would be annoying if we had to wait 30 minutes to get code in the agent running so we could debug it

When we are debugging we can force service to launch itself Such code can be conditionally compiled and removed before the

production version is built

#if DEBUG_AGENT ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60));#endif

Page 19: What's new in Windows Phone Mango for Developers

Windows Phone 20

Debugging the Agent Code

When you use the Back button or Start on the phone to interrupt an application with an active Background Task ,Visual Studio does not stop running

It remains attached to the application You can then put breakpoints into the background task application

and debug them as you would any other program You can single step, view the contents of variables and even change

them using the Immediate Window This is also true if you are working on a device rather than the

emulator The same techniques work on ResourceIntensiveAgents

Page 20: What's new in Windows Phone Mango for Developers

Demo

Demo2: Debugging Tasks

Page 21: What's new in Windows Phone Mango for Developers

Windows Phone 22

File Transfer Tasks

It is also possible to create a background task to transfer files to and from your application’s isolated storage

The transfers will continue to work even when the application is not running

An application can monitor the state of the downloads and display their status

Files can be fetched from HTTP or HTTPs hosts At the moment FTP is not supported

The system maintains a queue of active transfers and services each one in turn

Applications can query the state of active transfers

Page 22: What's new in Windows Phone Mango for Developers

Windows Phone 23

Background Transfer Policies

There are a set of policies that control transfer behavior Maximum Upload file size: 5Mb Maximum Download file size over cellular (mobile phone) data:

20Mb Maximum Download file size over WiFi: 100Mb

These can be modified by setting the value of TransferPreferences on a particular transfer

Page 23: What's new in Windows Phone Mango for Developers

Windows Phone

Transfer Management

An application can find out how many file transfers it has active It will have to do this when it is restarted, as file transfers will

continue even when the application is not running It can then perform transfer management as required There is a good example of transfer list management on MSDN:

http://msdn.microsoft.com/en-us/library/hh202953.aspx

Page 24: What's new in Windows Phone Mango for Developers

Demo

Demo3: Picture Fetch

Page 25: What's new in Windows Phone Mango for Developers

Windows Phone 26

Scheduled Notifications

Time-based, on-phone notifications Supports Alerts & Reminders Persist across reboots Adheres to user settings Consistent with phone UX

Page 26: What's new in Windows Phone Mango for Developers

Alarms vs Reminders? Alarms

27

Reminders

•Modal•Snooze and Dismiss•Sound customization•No app invocation•No stacking

• Rich information• Integrates with other

reminders• Snooze and Dismiss• Launch app• Follows the phones global

settings

Page 27: What's new in Windows Phone Mango for Developers

Windows Phone 28

Creating a Reminder

This code creates a reminder and adds it as a scheduled service The value eggTime holds the length of the delay This code also sets the url of the page in the application

using Microsoft.Phone.Scheduler;...eggReminder = new Reminder("Egg Timer");

eggReminder.BeginTime = DateTime.Now + new TimeSpan(0, eggTime, 0);eggReminder.Content = "Egg Ready";eggReminder.RecurrenceType = RecurrenceInterval.None;eggReminder.NavigationUri = new Uri("/EggReadyPage.xaml", UriKind.Relative);

ScheduledActionService.Add(eggReminder);

Page 28: What's new in Windows Phone Mango for Developers

Windows Phone 29

Reminder Housekeeping

Reminders are identified by name This code finds the “Egg Timer” reminder and then removes it from

the scheduler

Reminder eggReminder = ScheduledActionService.Find("Egg Timer") as Reminder;

if ( eggReminder != null ) { ScheduledActionService.Remove("Egg Timer");}

Page 29: What's new in Windows Phone Mango for Developers

Demo

Demo4: Egg Timer

Page 30: What's new in Windows Phone Mango for Developers

Windows Phone 31

Audio Playback Agents It is also possible to

create an Audio Playback Agent that will manage an application controlled playlist

The mechanism is the same as for other background tasks

The audio can be streamed or held in the application isolated storage

Page 31: What's new in Windows Phone Mango for Developers

Windows Phone 32

Background Audio Playback

App provides URL or stream to Zune Audio continues to play even if app is closed App is notified of file or buffer near completion

Phone Integration Music & Video Hub Universal Volume Control (UVC), launch app, controls, contextual info Contextual launch – Start menu, UVC, Music & Video Hub

App Integration App can retrieve playback status, progress, & metadata Playback notification registration

Page 32: What's new in Windows Phone Mango for Developers

Demo

Demo 5: Audio

Page 33: What's new in Windows Phone Mango for Developers

Tiles and Notifications

Page 34: What's new in Windows Phone Mango for Developers

Windows Phone

Consumer Experience Windows phone has the unique ability

to provide the end user glanceable access to the information they care most about, via Live Tiles

+ Push Notifications offer developers a

way to send timely information to the end user’s device even when the application is not running, including Tile updates

Page 35: What's new in Windows Phone Mango for Developers

Windows Phone

Tiles 101

Shortcuts to apps

Static or dynamic

2 sizes: small & large Large only for

1st party apps End-user is in

control

Page 36: What's new in Windows Phone Mango for Developers

Windows Phone

Data Driven Template Model

A fixed set of data properties Each property corresponds to a UI

element Each UI element has a fixed

position on screen Not all elements need to be used Animations are not extensible

Background Image

(173 x 173 .png)

Title Count

Page 37: What's new in Windows Phone Mango for Developers

Windows Phone

Scenarios/Popular Applications

Send to WP7 Link Tile Link Toast

AlphaJax Turn Tile Move Toast

Seattle Traffic Map Traffic Tile

Weather Apps Weather Tile Warning Toast

Chess by Post Turn Tile Move Toast

Beezz Unread Tile Direct Toast

There are hundreds and hundreds of Push apps in Marketplace!

Page 38: What's new in Windows Phone Mango for Developers

Windows Phone

Primary and Secondary Tiles Application Tile

Pinned from App List Properties are set initially in the

Application Manifest

Secondary Tile New in Windows Phone 7.5! Created as a result of user input in an

application

Front

Back

Page 39: What's new in Windows Phone Mango for Developers

Windows Phone

Live Tiles – Local Tile API

Local tile updates (these are *not* push) Full control of all properties when your app

is in the foreground or background Calorie counter, sticky notes

Multi-Tile! Deep-link to specific application sections Launch directly to page/experience

Application TileLaunches main app experience

Secondary TileLaunches world news page

Secondary TileLaunches local news page

Page 40: What's new in Windows Phone Mango for Developers

Windows Phone

Live Tiles – Local Tile API Continued… Back of tile updates

Full control of all properties when your app is in the foreground or background

Content, Title, Background

Flips from front to back at random interval Smart logic to make flips asynchronous

Title

Content

Title

BackgroundContent string is bigger

Page 41: What's new in Windows Phone Mango for Developers

Demo

Demo 1: Live Tiles – Local Tile API

Page 42: What's new in Windows Phone Mango for Developers

Windows Phone

Tile Schedule

Periodically updates the tile image without pushing message though Updates images only from the web, not from the app local store Sets up notification channel and binds it to a tile notification Few limitations

Image size must be less than 80 KB Download time must not exceed 60 seconds Lowest update time resolution is 60 minutes If the schedule for an indefinite or finite number of updates fails too

many times, OS will cancel it Update recurrence can by Onetime, EveryHour, EveryDay, EveryWeek

or EveryMonth

Page 43: What's new in Windows Phone Mango for Developers

Windows Phone

Scheduling Tile Updatepublic partial class MainPage : PhoneApplicationPage {    private ShellTileSchedule _mySchedule;    public MainPage()   {        InitializeComponent();        ScheduleTile();    }

     private void ScheduleTile()    {        _mySchedule = new ShellTileSchedule();        _mySchedule.Recurrence = UpdateRecurrence.Onetime;        _mySchedule.StartTime = DateTime.Now;        _mySchedule.RemoteImageUri = new

Uri("http://cdn3.afterdawn.fi/news/small/windows-phone-7-series.png");        _mySchedule.Start();    }}

Page 44: What's new in Windows Phone Mango for Developers

Windows Phone

Updating Tiles from a Background Agent In Windows Phone OS 7.0, only way of updating Live Tiles was from a Tile Schedule or

from Notifications

Tile Schedule needs to fetch images from a web URI

Notifications require you to implement a backend service

To have control of shell tiles when the app is not running without using Push Notifications, a good solution is a Background Agent

Use the ShellTile API to locate and update tiles

Page 45: What's new in Windows Phone Mango for Developers

Demo

Demo 2: Updating Tiles from a Background Agent

Page 46: What's new in Windows Phone Mango for Developers

Windows Phone

Push Notifications

Server-initiated communication Enable key background scenarios Preserve battery life and user

experience Prevent polling for updates

Page 47: What's new in Windows Phone Mango for Developers

Windows Phone

Push Notification Data Flow

URI to the service:"http://notify.live.com/throttledthirdparty/01.00/

AAFRQHgiiMWNTYrRDXAHQtz-AgrNpzcDAwAAAAQOMDAwMDAwMDAwMDAwMDA"

Push enabled applications

Notifications service HTTP POST the

message

Push endpoint is established. URI is created for the endpoint.

1

2

3

3rd party service

Microsofthosted server

Send PN Message

4

Page 48: What's new in Windows Phone Mango for Developers

Windows Phone

Three Kinds of Notifications

Raw Notification message content is application-specific Delivered directly to app only if it is running

Toast Specific XML schema Content delivered to app if it is running If app is not running, system displays Toast popup using notification message content

Tile Specific XML schema Never delivered to app If user has pinned app tile to Start screen, system updates it using notification message

content

Page 49: What's new in Windows Phone Mango for Developers

Windows Phone

Push Notifications – New Features

Multi-Tile/Back of Tile Support Multiple weather locations, news categories, sports

team scores, twitter favorites Can update all tiles belonging to your application

No API Change for binding tiles BindToShellTile now binds you to all tiles Send Tile ID to service and use new attribute to direct

update Three new elements for back of tile properties

Page 50: What's new in Windows Phone Mango for Developers

Windows Phone

Toast Notification

App icon and two text fields Time critical and personally

relevant Users must opt-in via app UI

Page 51: What's new in Windows Phone Mango for Developers

Windows Phone

Response Custom Headers

Response Code: HTTP status code (200 OK) Notification Status

Notification received by the Push Notification Service For example: “X-NotificationStatus:Received”

DeviceConnectionStatus The connection status of the device //For example: X-DeviceConnectionStatus:Connected

SubscriptionStatus The subscription status //For example: X-SubscriptionStatus:Active

More information http://msdn.microsoft.com/en-us/library/ff402545(v=VS.92).aspx

Page 52: What's new in Windows Phone Mango for Developers

XNA and Silverlight integration

Page 53: What's new in Windows Phone Mango for Developers

Windows Phone

Xna and Silverlight combined

It is now possible to create an application that combines XNA and Silverlight

The XNA runs within a Silverlight page This makes it easy to use XNA to create gameplay

and Silverlight to build the user interface Possible to put Silverlight elements onto an XNA

game screen so the user can interact with both elements at the same time

57

Page 54: What's new in Windows Phone Mango for Developers

Windows Phone

Creating a Combined Project

This project contains both Silverlight and XNA elements

58

Page 55: What's new in Windows Phone Mango for Developers

Windows Phone

A combined solution

A combined solution contains three projects The Silverlight project An XNA library project The content project

These are created automatically by Visual Studio

59

Page 56: What's new in Windows Phone Mango for Developers

Windows Phone

The XNA GamePage The XNA gameplay is displayed

on a specific Silverlight page that is added to the project when it is created

When this page is navigated to the XNA game behind it will start running

However, the Silverlight system is still active around it

60

Page 57: What's new in Windows Phone Mango for Developers

Windows Phone

Starting a Combined Application

When the combined application starts the MainPage is displayed

It contains a button that can be used to navigate to the game page

You can build your own game menu and start screen here

61

Page 58: What's new in Windows Phone Mango for Developers

Windows Phone

private void Button_Click(object sender, RoutedEventArgs e){ NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));}

Navigating to the game page

This is the button event hander in MainPage.xaml.cs Navigating to the page will trigger the XNA gameplay

to start

Page 59: What's new in Windows Phone Mango for Developers

Windows Phone

The game page

These are the methods on the game page that contorl gameplay OnNavigatedTo will do the job of the Initialize and

LoadContent methods OnNavigatedFrom is used to suspend the game OnUpdate is the Update method OnDraw is the Draw method

protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e)private void OnUpdate(object sender, GameTimerEventArgs e)private void OnDraw(object sender, GameTimerEventArgs e)

Page 60: What's new in Windows Phone Mango for Developers

Windows Phone

Combining XNA and Silverlight

The default combined project does not contain any XAML content for the XNA page

If XAML elements are added to this page they will not be displayed without some extra code The Silverlight page is rendered to a texture which

is drawn in the XNA game We have to add the code to do this

<!--No XAML content is required as the page is rendered entirely with the XNA Framework-->

Page 61: What's new in Windows Phone Mango for Developers

Demo

6: Silverlight and XNA

Page 62: What's new in Windows Phone Mango for Developers

Windows Phone

Summary

Get the new tools at http://create.msdn.com

Windows Phone Mango Jumpstart

66