Flying? Don’t forget your apps !!

Posted: March 9, 2011 in Mobile

Learnt a little lesson off late; that is what this post will be about. I have been working on big Windows Phone 7 app (actually the soon to be available Sogeti Hub) along with a couple of buddies. We were code complete and testing edge cases while having the app deployed on my HTC HD7. Then, on a recent flight to Florida, I just felt like running the app with no data access. Ooopsie .. nasty crashes everywhere!

Well, you need not always have to buy plane tickets in order to test your apps; the point is all mobile apps need to be well tested for gracious failures in “Airplane Mode”. I think we developers have gotten a little spoilt with increased computing power & high speed data connectivity. Mobile solutions, kind of, bring us down to the details again where we need to worry about lean performance & not assume ubiquitous data connectivity/location services. A well designed mobile app could have a lot of cloud support; but has to account for unavailability of resources and be mindful of user experience.

All that said, here are some details on where I had gone wrong. This is WP7 & Silverlight stuff, but should apply to corresponding things in other platforms. There were multiple instances where I was consuming RESTful API and in .NET, my favorite & possibly easiest way to go across asking for data is the “WebClient” class. Since Silverlight does not allow UI thread blocking, most web requests take this form:

WebClient objName = new WebClient();
objName.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EventHandlerName);
objName.DownloadStringAsync(someDestinationURI);

 

Essentially, the idea is to wire up an event handler, fire off a call & expect the event handler to execute when we have a response. Now, my event handler was conservative & checked for any error first up, like this:


private void EventHandlerName (object sender, DownloadStringCompletedEventArgs e)
 {
 if (e.Error != null)
 {
 // Do some error handling here.
 }
 else
 {
 // Move on happily with life.
 }
}

 

Now, here is the BIG DIFFERENCE. While testing in the emulator, I had shut off all connectivity on my laptop. Interestingly, the event handler always fired & we caught the error in the handler. While the app is running on phone in “Airplane Mode”, we never get to the event handler !! I am guessing this is because of how the “WebClient” class behaves; possible bug may be?

The safer solution is the enclose the “WebClient” call within a “Try-Catch” block and do immediate error handling if the “WebClient” class fails to make any progress. I would love to find out what unhandled exception was being thrown, and wish there was a way of debugging an app while it was using the data connections on the phone. Open question for me is how the “WebClient” class treats a phone in “Airplane Mode” differently as compared to a computer with no connectivity.

If anyone has the answer or had similar experiences, please drop a comment. Hope this was helpful.

Adios!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s