Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building Apps for Windows Phone 8.1 Jump Start

Similar presentations


Presentation on theme: "Building Apps for Windows Phone 8.1 Jump Start"— Presentation transcript:

1 Building Apps for Windows Phone 8.1 Jump Start
Andy Wigley | Technical Evangelist Matthias Shapiro | Program Manager / Technical Evangelist

2 Meet Andy Wigley | ‏@andy_wigley
Technical Evangelist in Microsoft Developer Experience and Evangelism (DX) Mobile developer for over a decade, worked with WAP, ASP.NET Mobile Controls, Windows Mobile and Windows Phone Co-presenter of Windows Phone Jump Start for versions 7.0, 7.1, 8 and now 8.1 Writer, Teacher and Presenter Blog at Written a number of books for Microsoft Press, including Mobile Development Handbook (don’t buy, unless you’re working with .NET Compact Framework on Windows Mobile/CE!) Frequent speaker at industry conferences on all topics mobile Rock-star (well, I play in a small – but popular – band )

3 Meet Matthias Shapiro | @matthiasshap
Program Manager, Microsoft Windows Phone Developer and Evangelist Long-time XAML developer, from WPF to Silverlight to Windows Phone Windows Phone Demo-Writer and Noise-Maker (blog, Twitter) Bigger bloggy things - Code snippets –

4 Course Topics Building Apps for Windows Phone 8.1
01 | Introducing the Windows Phone 8.1 App Development Platform 06 | Adapting UI for Different Screens and Orientations 02 | Getting Started Building Windows Runtime Apps 07 | Windows Runtime App Lifecycle 03 | Page Navigation and Data Binding in Windows Runtime Apps 08 | Localization and Globalization in Windows Runtime Apps 04 | Lists and List Items in Windows Runtime Apps 09 | Data Storage, Backup and Roaming 05 | Programming Page Controls and Page Transition Animations 10 | Sharing Files and Data in Windows Phone 8.1

5 Course Topics Building Apps for Windows Phone 8.1
11 | Background Tasks and Multitasking 16 | Interacting with User Data: Contacts and Appointments 12 | Maps, Geolocation and Geofencing 17 | Camera, Media and Audio in Windows Phone 8.1 13 | Networking, Mobile Services and Authentication 18 | Enterprise in Windows Phone 8.1 14 | Tiles, Notifications and Action Center 19 | Programming SQLite on Windows Phone 8.1 15 | Sensors and Proximity: NFC and Bluetooth 20 | Tooling and Diagnostics

6 Course Topics Building Apps for Windows Phone 8.1
21 | App packaging, monetization and publication 22 | Best practices: Building Universal Apps for Windows and Windows Phone 23 | Silverlight apps on Windows Phone 8.1

7 Background Tasks and Multitasking
Windows XAML+ Silverlight 8.1 Building Apps for Windows Phone 8.1 Jump Start Background Tasks and Multitasking Andy Wigley @andy_wigley Matthias Shapiro @matthiasshap 30 April 2014

8 In this module… Multitasking on Windows Phone
Programming background tasks Background tasks run in response to triggers Conditions on background task execution Push notifications trigger example

9 Mobile multitasking model
11/14/2018 Mobile multitasking model Apps not on screen are suspended However apps can provide real-time content even when suspended Live tiles or toasts Scheduled toasts and notifications OS brokered tasks Background tasks and agents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

10 Background Execution in WP8
Build 2014 11/14/2018 Background Execution in WP8 Scheduled Task PeriodicTask, ResourceIntensiveTask Background Transfer Service Background Location Tracking VOIP and Audio Agents © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

11 Windows Phone 8.1 Background Tasks
11/14/2018 Windows Phone 8.1 Background Tasks © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

12 Background tasks An app can register background tasks
Tasks are scheduled and run by the OS, but are background ‘extensions’ of the foreground app Same permissions from manifest, same storage, same file access, etc. Resource usage is constrained by the system Foreground app (if running) has limited communications with its tasks Tasks can fire progress/completed events into the foreground app Tasks can read/write the same storage as the foreground app Tasks can use toast, tile, badge UI An app’s existing task registrations can be queried from the system An app can have more than one background task

13 Creating a background task in your solution
11/14/2018 Creating a background task in your solution Add a new project to your solution Use the Windows Runtime Component template In your foreground app project, add reference to the Background Task project © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

14 Writing a background task
Background Task infrastructure can send a Cancelation notification if task is idle or not responding, but if memory cap is exceeded, task can be terminated without notification. Your task needs to be resilient to rude terminations without a Canceled event firing.

15 You register background asks to run in response to triggers firing
11/14/2018 You register background asks to run in response to triggers firing © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

16 Tasks run in response to triggers
Notes System Trigger Runs on a specified system event. Events: UserPresent/Away, NetworkStateChange, InternetAvailable, SessionConnected, ServicingComplete, TimeZoneChange Note: LockScreenApplicationAdded and LockScreenApplicationRemoved are not supported on Windows Phone TimeTrigger Runs on a frequency (minimum gap of 30 minutes) LocationTrigger Runs as user enters/leaves a geofenced location MaintenanceTrigger but only when the device is on AC power PushNotificationTrigger Runs in response to an incoming raw push notification sent to the app.

17 Tasks run in response to triggers
Notes RfcommConnectionTrigger Bluetooth: when an RFCOMM connection has been established. DeviceChangeTrigger Bluetooth: when an ACL connection has been created/destroyed. BluetoothSignalStrengthTrigger Bluetooth: when signal strength goes outside of bounds. GattCharacteristicNotificationTrigger Bluetooth: when a characteristic change is received from a Bluetooth LE device Note: ControlChannelTrigger, used on Windows to hold open a TCP/IP channel and trigger on incoming data, is not supported on Windows Phone

18 “run this task every 30 minutes if the internet is available”
Conditions Condition User[Not]Present Internet[Not]Available FreeNetworkAvailable BackgroundWorkCostNotHigh “run this task every 30 minutes if the internet is available”

19 Registration needs manifest entry
should not have to specify an executable for the background task host here.

20 Requesting background task access
11/14/2018 Requesting background task access © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

21 Requesting background task access
11/14/2018 Requesting background task access async void RegisterBackgroundTasks() { // On Windows, RequestAccessAsync presents the user with a confirmation // dialog that requests that an app be allowed on the lock screen. // On Windows Phone, RequestAccessAsync does not show any user confirmation UI // but *must* be called before registering any tasks var access = await BackgroundExecutionManager.RequestAccessAsync(); // A 'good' status return on Phone is BackgroundAccess.AllowedMayUseActiveRealTimeConnectivity if (access == BackgroundAccessStatus.Denied) // Either the user has explicitly denied background execution for this app // or the maximum number of background apps across the system has been reached // Display some informative message to the user... } © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

22 Battery Saver New in Windows Phone 8.1
11/14/2018 Battery Saver 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 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

23 Registering a background task
11/14/2018 Registering a background task BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.Name = "MyBackgroundTask"; // Many different trigger types could be used here SystemTrigger trigger = new SystemTrigger(SystemTriggerType.TimeZoneChange, false); taskBuilder.SetTrigger(trigger); taskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); // Entry point is the full name of our IBackgroundTask implementation // Good practice to use reflection as here to ensure correct name taskBuilder.TaskEntryPoint = typeof(MyBackgroundTask.TheTask).FullName; BackgroundTaskRegistration registration = taskBuilder.Register(); // Optionally, handle the progress/completed events of the task registration.Progress += registration_Progress; registration.Completed += registration_Completed; © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

24 Querying task registrations
11/14/2018 Querying task registrations // AllTasks is a dictionary <Guid, IBackgroundTaskRegistration> so you can get back // to your registration by id or by posiiton, or select First if you only have one registration. var taskRegistration = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(); // We could then unregister the task, optionally cancelling any running instance if (taskRegistration != null) { taskRegistration.Unregister(true); } // Release the progress/completed event subscriptions registration.Progress -= registration_Progress; registration.Completed -= registration_Completed; © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

25 Debugger can launch tasks
You can manually invoke your background task code using the debugger (once the registration code has been run)

26 Background tasks demo

27 Example: push notification trigger
11/14/2018 Example: push notification trigger © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

28 Push notification triggers
11/14/2018 Push notification triggers Football Score Cloud Service Windows Notification Service <?xml version=“1.0”> Type = raw, Data = Man City.... </xml> <?xml version=“1.0”> Type = raw, Data = Man City.... </xml> <?xml version=“1.0”> Type = raw, Data = End Game </xml> <?xml version=“1.0”> Type = raw, Data = Man City.... </xml> 0:32m Man City 1 Man Utd 0 Foreground App 0:47m Man City 1 Man Utd 1 Football News: Your Team Won! 0:85m Man City 2 Man Utd 1 3 2 1 Storage End: Man City 2 Man Utd 1 Push Background Task 4 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

29 Push Notifications trigger
demo

30 Resource constraints

31 11/14/2018 Resource constraints All background tasks have CPU, memory and network quotas Quotas are based on actual CPU usage instead of wall clock time limits only. On Windows Phone, CPU usage quota is 2 seconds per app, refreshed every 15 minutes. Wall-clock CPU quota will also be enforced (at least 30 secs) Memory quota scales based on device capabilities TimeTrigger will have a 30 min floor on Phone Call RequestAccessAsync() to get your full quota! On 512MB devices, number of background apps is limited If exceeded, call to RequestAccessAsync will return Denied © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

32 Memory Caps in MB Background task type 512 MB 1 GB 2 GB or greater
11/14/2018 Memory Caps in MB Background task type 512 MB 1 GB 2 GB or greater Location 16 30 40 Bluetooth Servicing Complete 10 Other background tasks Limit while debugging 50 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

33 Not supported in Windows Phone Store Apps
Apps that run under the lock-screen Continuous background location tracking apps VoIP agent (incoming call, progress etc.) Foreground agents (WalletAgent)

34 Related topics Background audio Background file transfer service
See Session 17: Camera, Media and Audio Background file transfer service See Session 13: Networking and Mobile Services Notification mechanisms See Session 10: Tiles, badges and toasts and Notification Center

35


Download ppt "Building Apps for Windows Phone 8.1 Jump Start"

Similar presentations


Ads by Google