2

Are there any Monotouch multitasking sample I can download?

I'm having problems in finding out best practice using multitasking with Monotouch. How I should handle when user presses home button, my application goes to the background, reopens my program and I must show where he left off (how to show the correct form/view) ... a sample of that would I love to see.

Thanks! Morten

MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • Do you mean something that uses threads? – Candide Nov 27 '11 at 13:51
  • Nope ... how I should handle when user presses home button, my application goes to the background, reopens my program and I must show where he left off (how to show the correct form/view) ... a sample of that would I love to see. I edited my question. – MojoDK Nov 27 '11 at 13:58

2 Answers2

2

You will have to override the methods DidEnterBackground and WillEnterForeground in the AppDelegate class. Inside these methods, you will have to save the current state of the app on your own (eg. which controller was active, what data was displayed etc).

The implementation of DidEnterBackground should be lightweight. In case you need more time for your app before it gets suspended, check how you could do it in this blog post.

Dimitris Tavlikos
  • 8,170
  • 1
  • 27
  • 31
0

you don't need to do anything. that should be default behaviour on iPhones that supports Multitasking.

if not so check in you Info.plist for "UIApplicationExitsOnSuspend" or "Application does no run in background" it should be NO.

JeanLuc
  • 4,783
  • 1
  • 33
  • 47
  • I have neither of those settings in my plist file. When I open my app, the splash screen is shown. If I press the home button and open my program again, the splash screen is shown again and all my variables are gone. So I can't figure out how best practice is to save the different view states and vars, so the user will be where he left. I don't want it either to show the splash screen again when opening my program that is sent to the background. Any idea? Thanks! – MojoDK Nov 27 '11 at 14:29
  • on what iPhone are you testing ? because only iPhone 3GS (or newer) with iOS 4 (or newer) supports multitasking. to make sure it's active you could add "UIApplicationExitsOnSuspend" with value "NO" to your plist – JeanLuc Nov 27 '11 at 14:41
  • @JeanLuc: this is not correct. When an app goes to the background and gets suspended, it is not guaranteed that when it is resumed, everything will be where it was last time. UIApplicationExitsOnSuspend set to "NO" is the same as not having it at all in Info.plist. – Dimitris Tavlikos Nov 27 '11 at 14:54
  • What to do then? I'm sad that Xamarin doesn't have a sample that show how to handle this. – MojoDK Nov 27 '11 at 16:12
  • @JeanLuc. I use the simulater iOS 5. – MojoDK Nov 27 '11 at 16:17
  • @ Dimitris: he never talked about that the app will be suspended. because it's not multitasking if the app is killed. – JeanLuc Nov 28 '11 at 10:36
  • @MojoDK the forms are probably everytime empty because you restart your app through MonoDevelop, which essentially kill the app and restarts it. – JeanLuc Nov 28 '11 at 10:37