views:

557

answers:

3

Hi, I want to develop an application in which if a method is in execution and user suddenly press home key. and the application exits. the application automatically restart and the method started to execute again from the point where it is closed.. Please guide me the best way.... Thankx in advance..

+2  A: 

This is basically impossible. To achieve the effect you want, you must express the state of the application in such a way that it can be quickly saved to the filesystem periodically and on exit, and then recovered from "disk" when you restart it.

I've never used CoreData but I suspect that it will support this kind of requirement quite naturally. Storing state in SQLite is another possibility. These are very different approaches with their own pros and cons, and the choice may come down to personal preference. I like SQLite because I can persist state incrementally and transactionally, without needing to regularly trigger a save-the-world operation (CoreData may also support this; I plead ignorance).

Marcelo Cantos
A: 

You can do it by using URL schema, read more here http://github.com/ltgbau/_SkyPaw_AutoRestartApp

ltgbau
+2  A: 
  1. Register to receive any UIApplicationWillTerminateNotification notifications
  2. When you receive the notification that the app will close, save your state by either saving information into NSUserDefaults or some other location more appropriate to your app.
  3. When your app restarts, you can rebuild state from the values you stored previously.

There's no automated way to do this that works for every app and it is a manual process, it's not hard, though.

Edit: here's Apple's example app to do this for a navigation based app: DrillDownSave

kubi