an end-to-end experience of windows phone 7 development (part 1)
DESCRIPTION
DevDays 2011 South Africa - An end-to-end experience of Windows Phone 7 development (Part 1)TRANSCRIPT
Rudi Groblerhttp://www.rudigrobler.net@rudigrobler
An end-to-end experience of Windows Phone 7 development
TRACK: NEXT GENERATION
agenda
Orientation
Tombstoning
ApplicationBar
Threading
Location
Performance
orientation support
PhoneApplicationPage.SupportedOrientations property states what orientations the page supports
PortraitLandscapePortraitOrLandscape
If set to PortraitOrLandscape, page will re-orientate itself automatically when the user rotates the phoneYou cannot force a page to re-orientate in codeYou can force a page to always use a specific orientation by setting the SupportedOrientations property to the value you required
Orientation using VSM
demo
orientation + SIP
SIP takes up more space landscape than portrait
vs
system tray and application bar
System TraySystem owned indicator area that display system-level status informationApps can show/hide
Application BarArea where applications can display buttons for the most common tasksCan display pop-up menu for less common tasks
application bar
Use the ApplicationBar instead of creating your own menu systemUp to 4 buttons plus optional menu
Swipe up the bar to bring up the menuAll buttons must specify Text property as well as IconUrl (Changed in Beta)
Don’t fill all 4 slots if not neededUse white foreground on transparent background for icons
System will colorize button according to users selected theme
Application bar
application bar
Page scoped – Search, etcNot for item specific actions like save/delete, rather use the ContextMenuAbove SIP
basic application lifecycle
Not Running
Launching
Running
Closing
Low Battery
a world of interruptions
Phone Calls
Lock Screen
Text Message
Reminders
Application Switch
Application lifecycle – the problem
moved to background
Running
Deactivate
Tombstoned
Activate
Fast switching a.k.a. dormant
Dormant
Tombstoned
Save state
Restore state
application management
Windows Phone execution model is designed to provide end users with a fast, responsive experience
Only one application can run at a timeSystem terminates application when user navigates away
Application is Tombstoned when user navigates awaySystem saves state information then terminates you applicationWhen user navigates back to the application system restarts the application and passes state information back
Developer must write code to respond to lifecycle eventsSave and restore stateMaintain illusion that the application is running continuously
Check if tombstoned (IsAppInstancePreserved)
lifecycle events - application
Application_LaunchingWhen the application is launching (from start)Not fired when the application is reactivated
Application_ActivatedWhen application is activated (brought to foreground)Not fired when the application is first launched
Application_DeactivatedWhen the application is deactivated (sent to background)Not fired when the application is closing
Application_ClosingWhen the application is closing (user hit back)Not fired when the application is deactivated
lifecycle events - page
OnNavigateToOnNavigateFrom
Application lifecycle – the solution
optimizing tombstoning (1)
Know what to savePivot.SelectedItem
TIP: Set in Loaded and NOT NavigateToPanorama.DefaultItemScrollViewer position (use ScrollPositionHelper)TextBox.TextViewModel
Where to savePhoneApplicationService.Current.State[]PhoneApplicationPage.State[]Cache to IsolatedStorage
When to saveApplication life cycle eventsPage-level OnNavigateFrom/OnNavigateTo
Do not save state on back navigation
optimizing tombstoning (2)
Optimize your storage formatsDataContractSerializerJSON.NET (MS implementation is VERY slow)XMLBinary (More work but VERY fast)
MUST rehydrate in less than 10 secondsDefer loading when possible
optimizing tombstoning (3)
Release resourcesCamera, Video, Location, Sensor, etc
On rehydrate/activate, remember GPS warm-up time
Framework will stop audio, sensors, networking, sockets, MediaElement & camera
Test your tombstoning!!!
phone threading model
•Primitive animations•Composite onto back bufferCompositor
•Rasterize•Binding•Layout•TouchUI•Dispatch•Networking•Parsing
Background
Touch thread
PerformanceProgressBar
“The ProgressBar template for Silverlight that is built into the Windows Phone today has a negative performance cost in ‘indeterminate’ mode (the animating dots that often indicate loading during an operation of
unknown time). The control is also known as ‘progress indicator’ according to the UX guidelines for the phone.”
Use PerformanceProgressBar (Available in the Silverlight Toolkit for Windows Phone)Read more on Jeff Wilcox’s blog:
http://bit.ly/PerformanceProgressBar
ProgressIndicator
LowProfileImageLoader
“LowProfileImageLoader is meant to address a very specific scenario: loading lots of images from the web at
the same time.”
Read more on David Anson’s blog:http://bit.ly/LowProfileImageLoader
Image decoding on background thread
Location
Location services
WiFi
+ Accuracy- Power- Speed- Indoors- Accuracy
+ Power+ Speed- Wilderness
+/- Accuracy+/- Power+/- Speed+/- Urban areas
Cell towers
Location
GeoCoordinateWatcher
Warm it upSingletonCan be disabled
persistence
All IO is restricted to Isolated StorageCreate files Manage Settings
Ideal for caching dataCheck out WP7Contrib and AgFx
Isolated Storage based Relational DBsSterlingSQLite
Structured storage
performance counters
Application.Current.Host.Settings.EnableFrameRateCounter = true;
MetricsCounter Ideal Min Best Experience Theoretical Max
Compositor Thread 30 fps 60 fps 120 fps
UI Thread 15 fps > 15 fps 120 fps
Screen Fill Rate 1.0 <= 2.0 N/A
push notifications
Server-initiated communicationEnable key background scenariosPreserves battery life and user experiencePrevents polling for updates
types of notifications
Toast
Tile
Deep toast
Push Notification Architecture
HTTP Post to URI with payload
Push URI request/response
Push enabled application
Push client service
Push client/server negotiation2
Push URI to Cloud Service
4
5
Push notification to device6
Cloud Service
MPNS
Windows Phone 7
13
Scenarios/Popular Applications
Weather TileWarning Toast
Weather Apps
Turn TileMove Toast
Chess by Post
Unread TileDirect Toast
Beezz
Link TileLink Toast
Send to WP7
Traffic Tile
Seattle Traffic Map
Turn TileMove Toast
AlphaJax
There are hundreds and hundreds of Push apps in Marketplace!
Windows Push Notification Server Side Helper Library
“The library provides an easy way for sending all three kinds of push notification messages currently supported by Microsoft Push Notification Services (MPNS):
Tile, Toast, and Raw. Our main goal here is to extract any complexity for sending push notification (PN) messages from your website (or web service) to a
Windows Phone. This library helps developers to send push messages using only a few lines of code.”
Read more on the Windows Phone Developer blog:http://bit.ly/PushNotificationHelper
don’t re-invent the wheel
Control ToolkitsPhoneyToolsCoding4Fun ToolkitSilverlight Toolkit for Windows PhoneWP7Contrib
MVVM ToolkitsMVVM LightCaliburn.Micro
DatabasesSterlingSQLiteAgFx
NuGet
text input
TextBox integrates with the software keyboardSoftware keyboard supports input scoping
Key InputScopes: EmailNameOrAddressTextUrlNumberTimeTelephoneNumber
PasswordBox has a 1 second delay
Text Text Revolution: A Game that Improves Text Entry on Mobile Touchscreen Keyboards
Text input
memory constraints
Do not use more than 90mb of RAMUse Coding4Fun Toolkit MemoryCounter
+/- 30% reduction in working set
Certification checklist
No network, no problem?<90MB?Theme aware?Handles exceptions?Back button works as expected?User consent dialogs & settings
Monitor your application
Add a “Send Feedback” buttonStore crash data and ask user to email itAnalytics
Slides, demos, etc…
@rudigrobler
http://www.rudigrobler.net
questions
Don’t forget the Xbox Kinect show-down
after sessions this evening!
DevDays 2011 Sponsors
PLATINUM SPONSORwww.bbd.co.za
SILVER SPONSORwww.dvt.co.za
SILVER SPONSORwww.ctutraining.co.za
Keep in Touch
facebook.com/msdevsa
@msdevsa
http://blogs.msdn.com/southafrica
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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.