In iOS 4, when a user presses the Home button, the running app will save the current state and go to background. However I'm developing an app and I don't want it to go to the background. I want it to kill itself, just like in iOS 3 and before. How can I do it? Thanks.
See "Opting Out of Background Execution" in the iOS Application Programming Guide:
"...you can explicitly opt out of the
background execution model by adding
the UIApplicationExitsOnSuspend key to
your application’s Info.plist file and
setting its value to YES."
Related
I am developing a navigation app, that needs to run in the background. I want to know how can I set background running time of app? And is this time fix by iOS?
Here you have the UIBackgroundModes
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
Scroll down and you will see that you can enable location in your info.plist
Good Luck with that one
In the latest iOS, apps now "deactivate" rather than close by default. So the app retains state and stays in memory.
I want my app to reset its state when it's reactivated, just like when it's closed/opened on iPhone 3.
I suspect reactivate is the wrong word! But hopefully you know what I mean.
thanks
Add the UIApplicationExitsOnSuspend key to your Info.plist, and set it to YES. This will mark your application as NOT supporting multitasking, and it will quit just like it used to. Good luck!
You can opt out of multitasking by setting the UIApplicationExitsOnSuspend key in your project’s Info.plist and setting the value to YES.
This will make your app behave like it would on iOS 3.x.
There's a property list key for that. UIApplicationExitsOnSuspend is set in your Info.plist when you want to exit instead of suspend when the user hits the home button.
If you have an app that you developed pre-multitasking and you are having issues or you don’t need it, you can disable multitasking in the application’s Info.plist file.
Adding
Application does not run in background
or
UIApplicationExitsOnSuspend
will stop your application being suspended when it is closed.
I'm trying to get the following functionality in my iPhone app:
When backgrounded, stays running (doesn't have to do any background work)
When resumed, app picks up where it was left off
I'm mainly wanting the same screen on my app still up, as there are several UINavigationControllers within a UITabBarController.
I have done all of the following:
Made sure I'm compiling with 4.1 SDK
Set UIApplicationExitsOnSuspend to false
Handle DidEnterBackground and WillEnterForeground in my AppDelegate
Call BeginBackgroundTask in DidEnterBackground, to attempt to keep my app open
I'm using MonoTouch, but that it probably beside the point. I can take answers in Obj-C, for sure.
I've tested my app on a jailbroken phone with Backgrounder, and I see the "app in background" badge disappear immediately after pushing the home button. I also tried setting UIBackgroundModes in my Info.plist, but to no avail.
Is there anything I'm missing?
Or is this something I would have to implement on my own to resume the previous state of my app? Everywhere I've read talks like it should just work automatically.
If you don't want to be doing work in background, don't call beginBackgroundTask. That call is for situations where you want to do some kind of work in the background. And if you don't finish that work fast enough, iOS will terminate your app.
When I upgraded to iOS 4.x, my MT application started exhibiting this behavior without me having to do anything. iOS should take care of it for you.
I finally got in touch with someone on MonoTouch's irc.
In MonoDevelop there is an option to make a dual iPad/iPhone project, which I used. This is causing my app to behave as if it's running with the 3.2 SDK when deployed to the device.
I think my solution is to install the iOS 4.2 SDK that just came out, since this ads the new multi-tasking feature on iPad.
Not only do you need to support going into the background, you also need to support cases where your app has been terminated. In your app’s initialization code, you should resume the state that it was in. For instance, when you push a view controller, use NSUserDefaults to store a value for the currently-displayed screen, and then when you start read that value and display the associated screen.
Example: My Default.png image shows the start screen of my app with an empty interface. When the app is launched from scratch the first time, this is cool. It appears like it started quickly. But when the user quits it and the app just goes to background, and then the user opens it, this sucks. Then I always end up with a wrong "snapshot" as launch image and my app then looks completely different after launch because it is like it was left the last time.
I would have to disable the Default.png when my app just goes to background, or I would have to enable it when it gets really terminated. Any way to do this?
It sounds to me like your app isn't being suspended. Every app that I've used that supports fast-app switching hasn't shown its default png when I open it after suspending it.
Are you sure your app is supporting fast-app switching and that it is being suspended?
Just updating my answer for some clarity that was revealed in the comments:
In order to take advantage of fast-app switching, the following conditions need to be met:
App needs to be compiled against the 4.0 SDK
App needs to be running on a multitasking-capable device such as:
iPhone 4
iPhone 3GS
iPod touch 3rd Generation
info.plist must not contain the UIApplicationExitsOnSuspend key.
I loaded some app projects that I had been developing using the iPhone 3.1.3 Simulator. Now I got the 4.0 package, and for some reason when I hit the home button of the simulator to go the home screen and then go back to the app, it's in the same position as I left it. Is this now standard? What if I don't want it to do this? I'd rather have it restart every time.
What you're describing is fast App switching, which is new in iOS 4.
If you want your application to quit each time the user presses the Home button, add the UIApplicationExitsOnSuspend property key to your info.plist and set it to YES (check the box).