What's new in Windows Phone Mango for Developers

1,819 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,819
On SlideShare
0
From Embeds
0
Number of Embeds
93
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

What's new in Windows Phone Mango for Developers

  1. 1. Highlights of What’sNew in WindowsPhone MangoGlen GordonDeveloper Evangelist, Microsofthttp://glengordon.name
  2. 2. Topics Fast Application Switching Background Agents Live Tiles XNA/Silverlight integration Windows Phone
  3. 3. DemoDemo 1:Fast Application Switching
  4. 4. Application Lifecycle - Dormant App Resume Fast runningState preserved!e.IsApplicationInstancePreserved Save State!== true activated deactivated dormant Phone resources detached Threads & timers suspended Windows Phone
  5. 5. Application Lifecycle - Tombstoned .. Resuming .Restore state!e.IsApplicationInstancePreserved running== false activated deactivated Tombstone Tombstoned dormant Phone resources detached the oldest Threads & timers suspended app Windows Phone
  6. 6. Methods & Events Windows Phone 6
  7. 7. Finding the Resume type private void Application_Activated(object sender, ActivatedEventArgs e) { if (e.IsApplicationInstancePreserved) { // Dormant - objects in memory intact } else { // Tombstoned - need to reload } } The Activation handler can test a flag to determine the type of resume taking place Windows Phone
  8. 8. Deactivation Resource Management MediaPlayer.Pause MediaElement.Pause SoundEffectInstance.Pause VibrateController.Stop PhotoCamera.Dispose Save page/global state XNA Audio Paused Sensors Notifications suppressed Networking Cancelled Sockets Disconnected MediaElement Disconnected Camera Disposed Windows Phone
  9. 9. Activation Resource Management MediaElement.Source/Position/Play Socket.ConnectAsync new PhotoCamera/VideoCamera Restore app state if tombstoned XNA Audio Resumed Sensors Notifications resumed Networking Completed with Cancellation Sockets - MediaElement - Camera - Windows Phone
  10. 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 Windows Phone 10
  11. 11. Captain’s LogDemo• With No Storage• With Storage• Fully Working
  12. 12. Background Tasks
  13. 13. Multitasking Capabilities Background Agents  Periodic  Resource Intensive Background Transfer Service Alarms and Reminders Background Audio Windows Phone 14
  14. 14. 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 Windows Phone
  15. 15. Generic Agent TypesPeriodic Agents Resource Intensive Occurrence Agents  Every 30 min  Occurrence Duration  External power  ~15 seconds  Non-cell network Constraints  Duration  <= 6 MB Memory  10 minutes  <=10% CPU  Constraints  <= 6 MB Memory16
  16. 16. Background Agent Functionality Allowed Restricted  Tiles  Toast  Display UI  Location  XNA libraries  Network  Microphone and Camera  R/W ISO store  Sensors  Sockets  Play audio (may only use background audio APIs)  Most framework APIs17 Windows Phone
  17. 17. DemoDemo1: Captain’s Location Log
  18. 18. Debugging a Background Task #if DEBUG_AGENT ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60)); #endif 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 Windows Phone 19
  19. 19. 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 Windows Phone 20
  20. 20. DemoDemo2: Debugging Tasks
  21. 21. 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 Windows Phone 22
  22. 22. 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 Windows Phone 23
  23. 23. 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 Windows Phone
  24. 24. DemoDemo3: Picture Fetch
  25. 25. Scheduled Notifications Time-based, on-phone notifications Supports Alerts & Reminders Persist across reboots Adheres to user settings Consistent with phone UX Windows Phone 26
  26. 26. Alarms vs Reminders?Alarms Reminde rs • Modal • Rich information • Snooze and Dismiss • Integrates with other reminders • Sound customization • Snooze and Dismiss • No app invocation • Launch app • No stacking • Follows the phones global settings27
  27. 27. Creating a Reminder 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); 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 Windows Phone 28
  28. 28. Reminder Housekeeping Reminder eggReminder = ScheduledActionService.Find("Egg Timer") as Reminder; if ( eggReminder != null ) { ScheduledActionService.Remove("Egg Timer"); } Reminders are identified by name This code finds the “Egg Timer” reminder and then removes it from the scheduler Windows Phone 29
  29. 29. DemoDemo4: Egg Timer
  30. 30. 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 Windows Phone 31
  31. 31. 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 Windows Phone 32
  32. 32. DemoDemo 5: Audio
  33. 33. Tiles andNotifications
  34. 34. 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 Windows Phone
  35. 35. Tiles 101 Shortcuts to apps Static or dynamic 2 sizes: small & large  Large only for 1st party apps End-user is in Windows Phone
  36. 36. 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 Background Image (173 x 173 .png) Title Count Windows Phone
  37. 37. Scenarios/Popular Applications Weather Apps  Send to WP7  Weather Tile  Link Tile  Warning Toast  Link Toast Chess by Post  AlphaJax  Turn Tile  Turn Tile  Move Toast  Move Toast Beezz  Seattle Traffic Map  Unread Tile  Traffic Tile  Direct Toast Windows Phone
  38. 38. Primary and Secondary Tiles Application Tile Front  Pinned from App List  Properties are set initially in the Application Manifest Bac k Secondary Tile  New in Windows Phone 7.5!  Created as a result of user input in an application Windows Phone
  39. 39. 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 Windows Phone
  40. 40. Live Tiles – Local Tile APIContinued… Back of tile updates  Full control of all properties when your app is in the foreground or background  Content, Title, Background Content Content string is Background bigger Title Title  Flips from front to back at random interval  Smart logic to make flips asynchronous Windows Phone
  41. 41. DemoDemo 1: Live Tiles – Local Tile API
  42. 42. 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 Windows Phone
  43. 43. 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(); }} Windows Phone
  44. 44. Updating Tiles from a BackgroundAgent 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 Windows Phone
  45. 45. DemoDemo 2: Updating Tiles from a BackgroundAgent
  46. 46. Push Notifications Server-initiated communication Enable key background scenarios Preserve battery life and user experience Prevent polling for updates Windows Phone
  47. 47. Push Notification Data Flow 2 URI to the service: "http://notify.live.com/throttledthirdparty/01.00/AAFRQHgiiMWN 3rd party Push enabled TYrRDXAHQtz- service applications AgrNpzcDAwAAAAQOMDAwMDAwMDAwMDAwMDA" 3 Notifications service HTTP POST the 4 message Send PN Message1 Push endpoint is established. URI is created for the endpoint. Microsoft hosted server Windows Phone
  48. 48. 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 Windows Phone
  49. 49. 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 Windows Phone
  50. 50. Toast Notification App icon and two text fields Time critical and personally relevant Users must opt-in via app UI Windows Phone
  51. 51. 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 Windows Phone
  52. 52. XNA and Silverlightintegration
  53. 53. 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 Windows Phone 57
  54. 54. Creating a Combined Project This project contains both Silverlight and XNA elements Windows Phone 58
  55. 55. 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 Windows Phone 59
  56. 56. 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 Windows Phone 60
  57. 57. 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 Windows Phone 61
  58. 58. Navigating to the game pageprivate void Button_Click(object sender, RoutedEventArgs e){ NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));} This is the button event hander in MainPage.xaml.cs Navigating to the page will trigger the XNA gameplay to start Windows Phone
  59. 59. The game pageprotected 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)  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 Windows Phone
  60. 60. Combining XNA and Silverlight <!--No XAML content is required as the page is rendered entirely with the XNA Framework--> 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 Windows Phone
  61. 61. Demo6: Silverlight and XNA
  62. 62. Summary Get the new tools at http://create.msdn.com Windows Phone Mango Jumpstart Windows Phone 66

×