tags:

views:

53

answers:

3

Hello All,

I want to remember the last screen of my app, means if I reopen my app, app should navigate me to the last screen where I were just before exiting app.

Thanks Saurabh

A: 

in iOS4 it's done automatically, because when you quit your application it's actually enters the background mode and doesn't quit. So when you "launch" it again, it opens at the same place the user left.

Previous versions of iOS don't have this feature and you should take care of it by yourself.

Nava Carmon
Thanks but I need this in iPhone OS 3.0... I need a pointer on how should I do this.. I know I can do this in applicationWillTerminate... but any other idea (with less efforts) will be much appreciated..
Saurabh
+1  A: 

Take a look at the NSUserDefaults API.

You could save an object for the current screen in the NSUserDefaults then check for that object on launch.

Create a NSMutableDictionary object when a view loads, and change it's value each time, and store it in the user defaults.

NSMutableDictionary *currentScreen = [[NSMutableDictionary alloc] init];
[currentScreen setObject:@"AboutPage" forKey:@"screen"];

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:currentScreen forKey:@"lastScreen"];

Then when the app loads, check the user defaults "lastScreen" key and load the appropriate view.

Hope this helps.

Joshua
A: 

Depending on your application, you may want to think about using the Three20 library. This library has the sort of persistence you are looking for built in.

gnuchu