Samstag, 4. Juni 2011

Windows Phone: Mango tombstoning news

 

Mango_ExecutingModel

With the Mango update of Windows Phone to Windows Phone 7 many things will be changed. One of them is a better support for mutitasking behaviour of your application. This package consists of new background tasks (a will report about this later) and a new state in the executing model of Windows Phone.

The new state

Until Mango, an Windows Phone app will be tombstoned (=process will be killed), if the user leaves the app with the start menu button and call another application. With Mango Microsoft now introduce a new state for an application: “Dormant”. If there is enough memory left, the Windows Phone OS let the process of your app in memory until a other application process will kick it out. The user can than use the new function “Press and hold the back button for two seconds” to open the Mango fast switch application screen to return to one the dorming apps.

Is it really new?

But this state for your application is not really new. Because today with Windows Phone application development for version 7.0, you have to consider this state also. If you have a long running deactivation process, for example because of serialization, it could be that the user returns quicker back to your application than the deactivation is finished. In that case you have to handle the same behaviour that your old process is still running.

How to handle the revival

To distinguish between a activating of your app after tombstoning or revival you can use the IsApplicationInstancePreserved property of the ActivatedEventArgs in the Activated event of your app in that way:

private void ApplicationActivated(object sender, ActivatedEventArgs e)
{
    if (e.IsApplicationInstancePreserved)
    {
        ApplicationDataStatus = "application instance preserved.";
        return;
    }
 
    if (PhoneApplicationService.Current.State.ContainsKey("ApplicationDataObject"))
    {
        ApplicationDataStatus = "data from preserved state.";
        ApplicationDataObject = PhoneApplicationService.Current.State["ApplicationDataObject"] as string;
    }
}

Because in the case of application revival after the dormant state the constructors of your pages are not run through, you can define a bool variable which indicates in the NavigatedTo-Event if your application was tombstoned or not. It is not a good idea to create a static class with a starting state, which is set during the activating event, because the NavigatedTo of your page could be called earlier than the activated event (in case of long running deactivation, for example).

So best practice is to define a private member IsNewPageInstance, which is set to true within the page constructor.


bool isNewPageInstance = false;
 
// Constructor
public MainPage()
{
    InitializeComponent();
 
    this.isNewPageInstance = true;
            
}

In the NavigatedTo-Event we know now, if we have to restore our page state:

private void ApplicationActivated(object sender, ActivatedEventArgs e)
{
    if (e.IsApplicationInstancePreserved)
    {
        ApplicationDataStatus = "application instance preserved.";
        return;
    }
 
    if (PhoneApplicationService.Current.State.ContainsKey("ApplicationDataObject"))
    {
        ApplicationDataStatus = "data from preserved state.";
        ApplicationDataObject = PhoneApplicationService.Current.State["ApplicationDataObject"] as string;
    }
}

Testing of Tombstoning with the emulator

Another greeat new feature of the new Mango Windows Phone tools is that you can force the debugger to produce a tombstoning behaviour. The achieve this, you have to check a checkbox in the project properties of the debugging area.

image 

Conclusion

With the new state “dormant” and the fast switching ability of the Windows Phone OS for the Mango version in combination with the new backgound tasks Microsoft give us the tools of trade to emulate a better multitasking appearance. This behaviour is now similiar to other mobile plattforms and still assure a good battery life time. For me, a great step in the right direction.

Donnerstag, 2. Juni 2011

Windows Phone: Mango Turn-By-Turn Navigation

One of the cool new features of the Windows Phone 7 Mango release (Windows Phone 7.5) is the posibility to use turn by turn imagenavigation with voice guidance. This feature of Windows Phone Mango is integrated in the standard Bing Maps application and can use by developers from their own Windows Phone apps by the BingMapsDirectionsTask.

In my sample I have added two GeoCoordinate objects. One with my home place and the other with my working place at SDX AG. With the common concept of Windows Phone for interaction by using a Launcher or Chooser task you can then create a BingMapsDirectionsTask instance, set the locations as LabeledMapLocation to the start respectively end property of the BingMapsDirectionsTask and call the Show()-Method.

After this your application put in the background and the standard Bing Maps application will be called. Now you can use the standard turn by turn navigation features with voice guidance.

Conclusion

The new BingMapsDirectionsTask and turn-by-turn navigation features of the Bing Maps application of Windows Phone is a very cool function which will enable developers to build a new kind of Windows Phone applications. Furthermore all applications like “Where is my next bank or letter box” now can give the user the ability to give navigating instructions to this place.

 

Sample Code

private readonly GeoCoordinate destination;
 
private readonly GeoCoordinate target;
 
// Constructor
public MainPage()
{
    InitializeComponent();
 
    destination = new GeoCoordinate(49.907903, 8.510628); // Home
    target = new GeoCoordinate(50.139836, 8.742199); // SDX AG
}
 
private void NavigateButtonClick(object sender, RoutedEventArgs e)
{
    var bingMapsDirectionsTask = new BingMapsDirectionsTask();
 
    var destinationLocation = new LabeledMapLocation(
        "Home",
        destination);
 
    var targetLocation = new LabeledMapLocation(
        "SDX AG",
        target);
 
 
    bingMapsDirectionsTask.Start = destinationLocation;
    bingMapsDirectionsTask.End = targetLocation;
    bingMapsDirectionsTask.Show();
}

Freitag, 20. Mai 2011

Silverlight 5: Better MVVM support

With Silverlight 5 you have the posibilty to define Custome Markup Extensions. For example you can define a new extension MethodInvoke which calls the named method in your datacontext in this way. Not longer event triggers or something else necessary.

more information about Silverlight 5 Beta features: Here

image

Windows Phone 7- Fiddle Web traffic

Here is a nice solution for debugging Windows Phone 7 device network traffic with Fiddler. I tested this also using Intel My WiFi Technology instead of Connectify.

http://dotnetbyexample.blogspot.com/2011/05/debugging-windows-phone-7-device.html

Montag, 16. Mai 2011

Windows Phone 7: Update for Windows Azure Toolkit

Microsoft has now released the third update of the Windows Azure Toolkit for Windows Phone in less than two months – shows that they are hard working on good Windows Azure support for Windows Phone.

One of the new features is the support for Windows Azure Access Control Services.

More details here: Update to Windows Azure Toolkit for Windows Phone 7 « Michael S. Collier's Blog

Sonntag, 15. Mai 2011

Silverlight 5 goes to desktop application platform

With the new version Silverlight 5 (beta available) the sandbox of an Silverlight app will be nearly destroyed. If you run your Silverlight application in elevated trust mode as out-of-browser application you can access now to the whole local file system and using P/Invoke to call a Win32-Api function. This will give us as developers a total new scope for Silverlight applications. We can now concept Silverlight applications that have native access to local resources like scanners, 3rd party applications and the whole file system – I love this, because the necessity of using WPF nearly disappears.

Pete Brown give us a flavour of new Silverlight applications that uses several operating windows:

Silverlight 5: Working with Operating System Windows - Pete Brown's 10rem.net

Windows Phone 7– A taste of Mango for developers

The Mango update for Windows Phone 7 was announced at the Mix11 for end of 2011. But the capabilities of Mango are coming a little bit earlier to developers next month with the new Windows Phone tools.

Jese Liberty has now published a few code samples and decriptions for a few key features that will come with Mango.

SQL Server CE

Coming in Mango–Sql Server CE | Jesse Liberty

Access to Calendar and Contacts

Coming in Mango–Query the Contacts List | Jesse Liberty

Silverlight 4 as the new base brings

Coming in Mango–Implicit Styles | Jesse Liberty

Coming In Mango–ICommand | Jesse Liberty

Notifications - Reminders and Alarms

What’s Coming In Mango–Reminders | Jesse Liberty