Sudhindra Kovalam's Blog

My Geeky Blog

Archive for July 2010

Windows Phone 7 Design Considerations

with 4 comments

Windows Phone 7 is an amazing platform. It delivers what it promised. But the experience is not 100% complete. Now it’s up to us to complete the experience by developing some cool apps.

Now We all are aware that a Silverlight developer can easily develop apps for Windows Phone. Yeah, we still have all the Drag and Drop goodness, but we need to keep into consideration , when we are designing the application, that the target device is a phone with 1 GHz  single core processor , Most of us will develop apps on a Core 2 Duo machine.

Since, I have been playing around with Silverlight development experience, am not sure about whether these points are exactly applicable( as is) to XNA game development. But still, here it goes:

1. Keep the User Experience simple:

The Silverlight runtime on the phone does not exactly have a lot of raw processing power available, so it has been optimized accordingly. There are certain points that you need to take into consideration when designing UI for the phone.

– Keep it simple

Less Elaborate UI means Less Code means less activity which will lead to better performance

– Limit the activity on the UI thread

The UI thread must be limited to User interaction , accepting input etc.

– Leverage the Render thread

The render thread, is separate thread that will take care of simple animations etc. This will result in smoother User Experience ( Remember, customer experience comes first)

– Leverage the GPU of the phone

We have a dedicated GPU on the phone. Use it! And Since yours is the only program that runs in the foreground, you can design your app to leverage the GPU (and by that I meant justifiable usage , remember you are running on a small handheld device )

If you are interested in drilling down more, there was a nice session at MIX’10 on Silverlight performance on Windows Phone. Seema Ramchandani’s session on Silverlight performance on Windows Phone.

2. Make sure you only upload necessary data:

As you must be aware that on a small radio device, transmitting from the device can always prove to be more costly as compared to receiving transmission ( in terms of battery life). The Same principle applies here too.

Upload/ Send to server only the data you need to, Say for example, In your app, you receive an array if  say tasks, in which say you update some of these tasks, instead of sending the entire updated array to the server ( or your backend service) send across only some information, such as only the ID of the Task, property changed and the updated value.

This will result in overall better application performance as well as better battery life on the phone ( Very crucial IMO)

3. Deactivate Quickly

In WM 6.x, apps never had an exit option, There never was an event that would let us know that the app is about to get killed. So in order to overcome this danger, what people did was to save state of the application periodically.

Well in Windows Phone 7, You do have an App Closing and App Deactivating event. ( Not sure about what that means? , read my post on WP7 app life cycle). When you receive this event, you save data to the phone’s isolated storage/ or some backend service  and retrieve it back when the app activates again.

Now If your app is mammoth and needs to save a lot of data in the deactivating event, Your app will take time to tombstone. What this will lead to is a delay in the launched/chooser to show up making the phone run sluggish.

What we can do to overcome this is  to save state  periodically ( When people say OLD IS GOLD, they aren’t kidding, are they?)

We can do something on these lines:

    // Constructor
    public App()
    {
        UnhandledException += Application_UnhandledException;

        // Standard Silverlight initialization
        InitializeComponent();

        // Phone-specific initialization
        InitializePhoneApplication();

        // Add a Timer to save state Periodically
        DispatcherTimer dt = new DispatcherTimer();
        dt.Interval = new TimeSpan(0, 0, 0, 10); // 10 seconds
        dt.Tick += new EventHandler(dt_Tick);
    }

    void dt_Tick(object sender, EventArgs e)
    {
        //Dirty Flag is set, when something that has to saved 
        // in the application's state has changed.
        if (_dirtyFlag)
        {
            // Save state incrementally.
        }
    }

    // Code to execute when the application is deactivated (sent to background)
    // This code will not execute when the application is closing
    private void Application_Deactivated(object sender, 
        DeactivatedEventArgs e)
    {
        System.Diagnostics.
            Debug.WriteLine("Go to sleep...zzz");
        if (_dirtyFlag)
        {
            // Only save state if there is a change.
        }
    }


Well these are all the points i can think off as of now.

These may not be applicable to all apps that we will write on WP7 , But i believe it is “Good to Know / Things to ponder on, when designing my WP7 app” stuff.

Any suggestions/ comments/ thoughts/ abuses are welcome.

Written by sudheerkovalam

July 26, 2010 at 5:14 am

Windows Phone 7 Process Life cycle

with 6 comments

What was made clear at Mix’10 was that third party apps in Windows Phone 7 wont be able to multi task. The reason provided was that too many apps running in the background may make the app in foreground run slowly. Once an user sees that s/he will definitely say that “Windows Phone 7 Sucks!, It is very slow and sluggish”.

Well what If we say that we will need multi tasking and will use it judiciously? well AFAIK, not Third party app multi tasking will be available in V1 ( Not sure , if MSFT intends to publish an OTA update to add multi tasking later )

With Windows phone 7, what MSFT promised was no  sluggish interfaces and apps that consume various data service and provide all the information you need in one place. And Frankly speaking off, they have done a decent job.

So, No Multi tasking, What does that mean for us developers?

Well in order to answer this question, we need to understand how an app will live on the phone ( the Windows Phone off course Open-mouthed smile )

When the app is Launched:

The app that you , me and many more developers will write will need to be launched from either the start experience or application list. When we do this, (from the programmer’s perspective) , a new instance of our application is created.  Well this does mean that we do get to write event handlers for events such as application launched etc..

However anywhere in the app, when the user presses the Start Button and/or triggers a Launcher or a chooser ( such as ‘”send an SMS” , “send an email”) etc, Your app’s state is saved and your app is put to sleep.

This process is called as “Tombstoning”

Wp7 App lifecycle

Following are the main events that we can use in our app to make our app feel as if it were really running in the background

1. Launching Event

When the app is launched, the Launching Event is fired. we can use this event, (usually an empty method pre written for you in app.xaml.cs) which we can use to instantiate stuff from the isolated storage. For e.g. , say you have an app that depends on some XML files that you need to read when the app launches, this is the event for you!, Write the code in the launching event

2. Closing Event

When the user clicks navigates through the app, a stack of page navigation is maintained. When the user hits the back button, the user is taken to previous screen.

Now when the user keep on hitting back button through the first page of the app. The app gets terminated and the closing event is fired. You can now write some app level data that you wish to persist, to the phone’s isolated storage.

3. Activated Event

Your app can be in the foreground or can be replaced with some app in foreground on some Launcher (such as send an email, call etc..). This is when the app is tombstoned and it also becomes possible that the app might not get activated again. The user can open many such apps,knocking off your app from the application stack ( the back button relies on the application stack to take you to a page in the current app or some page in previous app you had launched.) If the user were to launch the app from the start screen, it would create a new instance of the app

Now it is also possible that the user can reactivate your app by pressing the back button and coming to your app or even after the launcher completes. This is when your app is activated again. The Activated Event is fired when your app is activated after , say you complete a phone call when you were using the app . This is a good place where you can reload data you had stored in persistent store ( such as textbox data ,selected item etc . If you intend to store data entered in textboxes and you want to persist it )

4. Deactivated Event.

If an application is running and is subsequently replaced in the foreground by another application or experience, the first application will be deactivated. There are several ways in which this state can be invoked. An application will be deactivated if the user presses the Start button or if the device timeout causes the lock screen to be engaged. An application will also be deactivated when it invokes a Launcher or a Chooser, helper applications that allow the user to perform common tasks such as taking a picture or sending an email. In any of these cases, the running application will be deactivated and the Deactivated event is raised.

 

// Code to execute when the application is launching (e.g., from Start)

// This code will not execute when the application is reactivated

private void Application_Launching(object sender, LaunchingEventArgs e)
{
  //Get Data from Isolated Storage or a web service etc...
  System.Diagnostics.Debug.WriteLine("In Application_Launching event"+
     "... Nice Place to Initialize your app");
}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
   System.Diagnostics.Debug.WriteLine("And We are back!!");
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
   System.Diagnostics.Debug.WriteLine("Go to sleep...zzz");
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
   System.Diagnostics.Debug.WriteLine("goodbye cruel world.");
}

 

Hope this blog post helps you understand the Windows Phone 7 app lifecycle.

I will try and cover many more details in further posts as and how I discover them Smile

Thanks for your support. I will be back with my next post in a few days

Written by sudheerkovalam

July 21, 2010 at 4:20 pm

My Experiences in Windows Phone 7 Development :Part 2

leave a comment »

In Recently concluded Community tech days in pune, we had a sizable audience for Windows Phone 7 development session by Mayur Tendulkar. I was there in the crowd and must say, It was a good session on WP7 🙂

While the in the crowd  I did realize that Not  many have started WP7 development, But still, If you have done some development using April CTP and are probably itching to download the July Beta of the tool, Behold  There are some breaking changes.

Changes in the July Beta :

1. You Cannot now use the Bing maps control for silverlight in WP7 projects :

This my friends was very misleading  in the April CTP, You must have noticed that using the Bing Maps for SL , you could actually create apps on the phone that utilize, however  the performance would have been really bad, even on the emulator (it used to take around 4-6 min to load the map ).

The SL controls used to work on the April CTP due to a glitch in the, then released SDK.

2. The issue of needing to use unsigned versions of the dll that were signed using third party certificates has now been resolved

In the April CTP, you  could not use a signed DLL from a third party , as the emulator would not allow you to use these DLLs, You would have needed to unsign these DLLs to use ‘em in your WP7 project.  the Good news is that this has now been fixed in the July Beta. Now You can use the singed DLLs that you always wanted to use

3. Some of the assemblies have been merged into a single assembly:

One thing that you will probably notice is that once you open your April CTP project after you install the beta tools, the project compilation will result into a lot of errors. Most of these have got to do with the assembly mergers and deprecation of certain controls. A more detailed blog has been written by Jamie Rodriguez from Microsoft , where this is explained in much more detail (Link to Jamie’s Blog)

Upgrading to the July Beta:

I have  heard a lot of complaining about the setup experience on upgrading from April CTP to july Beta. What I’d Suggest ( the way which worked smoothly for around 5-6 PCs in my office) is to uninstall the CTP by hitting the uninstall option for Windows Phone Developer tools CTP in the add/remove programs. This will uninstalll all the components and ask for a reboot. After the reboot is done, we can now start the installation of the July beta SDK and tools.

Issue that I have observed :

One thing, you might notice is that whenever you do a DateTime.Now in your code and you are running this code in the emulator, the emulator will always return the install date and not the system date. If this is an issue that you are facing there is a workaround for this. Go to %ProgramData%\Microsoft\XDE and delete all files with .dess extension there (These are the state files, once these are deleted you will see the current date on the emulator, However time zone is set to Alaska GMT -9). So Once you start noticing the offset, delete the .dess file and you are back on time 🙂

 

Much more to come in the following blog posts… Keep reading and thanks for your support

Written by sudheerkovalam

July 18, 2010 at 5:53 pm

My Experiences on Windows Phone 7 development : Part 1

leave a comment »

Wow. its been almost 6 months that I posted anything on my blog.

Anyways, I have been working on windows phone 7 for the past month or so.

This blog  post (of a series of blogs) will try and tell about my experiences of working on WP7.

First of all, We (As in our client, A Microsoft Partner Award 2010 winner) had an amazing demo at Worldwide Partner Conference. As you might have guessed, we worked on the demo and the actual product that will be unveiled soon.

I will put in my experience in much more details in days to come ( I will, I Promise!! )

Written by sudheerkovalam

July 14, 2010 at 2:02 am