ailon's DevBlog: Development related stuff in my life

Unimportant state in Windows Phone 7.0 apps can bite you on Mango

9/1/2011 5:40:40 PM

We’ve learned to preserve important state on tombstoning in 7.0 Windows Phone apps. But what about state we don’t care to preserve?

Most of the time we don’t care about the state of some variable so we don’t store it on deactivation and don’t restore it on activation. The smartest of us have probably thought about these members too, but I’m not one of them. Some of my code assumed that these fields are reset to their default/initial values, even though I’ve never thought about it explicitly.

Turns out when you recompile your app for Mango this state is actually preserved since your app’s process isn’t killed. When user returns to your app this “unimportant” object still has the same state as it was when the user left, but you may have programmed your app in a way that it assumes the state to be reset.

I was thinking about a good example to illustrate this, since my real situation was too cumbersome and specialized for a general purpose blog post. Suppose you have an app that does some processing. During the processing it shows a busy indicator or a progress bar and when it’s done it fires an EmailComposeTask with Body set to the results of your processing. In 7.0 if a user later returns to your app the process would be restarted and you would restore the important state. Is Visibility of the progress bar an important state you’d like to preserve? Probably not. But you probably expect it to be hidden, since it’s a default and the process is restarted. But are you sure you’ve collapsed it before firing the EmailComposeTask launcher? Chances are you haven’t, because you assumed it’s not an important thing to do, when user leaves your app anyway.

Not the most elegant example, I know. But you probably get the idea. It’s less critical to preserve the state of important objects in Mango, but you need to check your implicit assumptions about unimportant state being reset on return to the app.

Tags:

blog comments powered by Disqus
Copyright © 2003 - 2018 Alan Mendelevich
Powered by BlogEngine.NET 2.5.0.6