Fast Resume: Any tips and tricks?

poken1151

New member
Oct 30, 2012
132
0
0
Visit site
I've a personal problem with how App Resume works in WP. As more and more High profile or complex apps hit the store, I'm starting to get more and more peeved by how apps resume.

In my own apps, I only recently realized that after being tombstoned a user may end up losing everything they were working on despite my auto-save feature, mainly because of how resume works.

I did a fix to store certain DB items to reload on resume. But the user will never return to the same instance (this means, not the same position in a list, same text box highlighted etc.). And seeing other major apps either fully reload on resume (AoE) or stutter, lose place (Spotify) or just up and crash (a few games), I was wondering if anyone had found a good solid, resource on managing app resume.
 

Rafael Yousuf

New member
Oct 19, 2013
358
0
0
Visit site
Hi, addding resuming to your app is not really hard if you know how to use the "SuspensionManager.cs" class. Now to do a full reload of the page state in your app you will need to spend some time working on it.

Lets say the user was writing something in a text box and your app was suspending because the user got a call or tapped on a notification, When windows phone raises the "SaveState" event in your app you have to save the text in that text box to the suspension manager using code like this [C#]:
e.PageState["usernameTextBoxContents"] = this.username.Text;


Now after windows is done suspending your app, the user might go back to it, so it is expected that what the user typed in the text box is back, so windows will raise the "LoadState" event in your app and you need to do this: [again C#]:
if (e.PageState.ContainsKey["usernameTextBoxContents"] && e.PageState["usernameTextBoxContents"] != null) { //restore the text this.username.text = e.PageState["usernameTextBoxContents"].toString(); {


So whenever your app is suspended you will need to get the info you want to restore later and save it, it will take some work and time but it is very easy to do.

BTW: if you select the "BasicPage.xaml" template (in WP or WinRT) the suspension manager will be added and will keep track of the page the user was on before suspending. So you don't need to tell the Main App frame to go a certain page, just let the manager do ti for you.

also take a look at my app [it is beta for now] but it has the resuming capabilities in it: RTA Car Driver Knowledge Test Simulator BETA | Windows Phone Apps+Games Store (United States)

Hope this helped you
 
Last edited:

Im_Q

New member
Nov 26, 2012
119
0
0
Visit site
You didn't mention if this is for a Silverlight or Runtime app. If you haven't decided which type of app to write, definitely go with Runtime apps from a purely Fast App Resume point of view. After porting my Silverlight app to Runtime, Runtime apps seem to resume faster, more consistently, and far less buggy. Sometimes I would get weird behaviors like crashes, leftover page history even though I intentionally clear it, and of course performance issues where you see "resuming..." for a more extended period of time.

As for some complaints about resuming to same instance, it will if it was maintained in memory but it's not current possible if your app was terminated (ie: tombstoned). Your app is basically killed, and some small amount of data about its state is stored. Once relaunched in anyway (including task switcher), it's essentially restarted and then some code will try to restore previous state if any exists. As Rafael mentioned, to restore transient data (like uncommitted textbox entry or list position) your store away the key and restore it when you arrive at the page. There are also stuff that you don't have to worry about maintaining between tombstoning like which TextBox is in focus (even native apps lose focus when you navigate away like messaging app).
 

Members online

Forum statistics

Threads
326,609
Messages
2,248,629
Members
428,522
Latest member
BarkerJarrod