i am developing a ebook reader and i am facing the following issue. if i close the app and reopen , then it opens exactly in the same state as it used to be before closing. I suspect this may lead to a lot memory leaks. Is this the right way for the app to function? and will this behavior cause any memory leaks?? can anyone help me with this... I dint know what title to put on top.. Please apologize me if the title was misleading.. thank you.
This is the expected behavior. After the introduction of iOS4, applications will keep their state between launches. Applications get terminated when the system is running low on memory, as the system terminates applications not recently used to free memory. This will not lead to memory leaks. For users running iOS3 pressing Home will terminate the application.
See Understanding an Application’s States and Transitions and Multitasking for more information.
right appropriate code in delegate file
-(void)applicationDidEnterBackground:(UIApplication *)application
{//exit(0);
}
if nothing works write exit(0) in this method.
You can add the BOOL key: "Application does not run in background" to your info.plist and set it to YES. Then your app should be terminated when you press the home button.
Related
When my app is launched, and I double tap on the home button to display the bottom bar containing all the running application (multitasking), My App crashes, and I have no idea where it can come from !!
Any help please ?
Ok, I found it, actually I had nothing in the stack nor in the console log, except a "Program ended with exit code: 255", but that's I quit the application in the applicationWillResignActive, using exit(-1). Thanks anyway
Hallo Everyone,
with the iOS 4, the iPhone is supporting Multitasking, what is very nice, but something I do not wish to support in my Application. I mean, when the user press the Home-button, I want my application to finish and not to enter in Background. With the iOS 4, when the User press the Home-button, the App calls the applicationDidEnterBackground: delegate's method to enter in Background and in order to "force" the Application to finish when the user press the Home button, I've done following implementation:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//save everything...
exit(0);
}
PROBLEM: I've noticed, that exit(0) brings the Application immediately to finish, without calling deallocating methods like "dealloc", and I think that is not a good programming style. So I would like to ask you guys, how to bring the application to finish in a "nicer" way.
Thanks in advance.
What you actually want is not to exit the application (which is as mentioned not allowed), but tell the OS you would rather your application be killed rather than backgrounded.
There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated.
That's two questions:
How to programmatically exit an iPhone app - duplicate
Proper way to exit iPhone application?
How to cause an iPhone app to not go to background in iOS4:
Add the UIApplicationExitsOnSuspend key to your info.plist and set its value to YES
http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
One answer above says "There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated." with Xcode 4, the info.plist value is "Application does not run in background" of type Boolean, so setting this to YES will have the app exit when the user presses the "home" button.
You are not allowed to. I know from experience: got an app rejection from Apple because I've exited (that was two and a half years ago but I doubt they've changed their policy here). There's a "private" (i.e. not mentioned in header file) method "terminate" on UIApplication, IIRC. But Apple says you may not do that. Only thing you can do is to show a dialog, asking the user to press the home button. But in turn doesn't work if on a device with multitasking enabled... so I guess you really have to change your application in such a way that you can throw away your state on applicationDidEnterBackground and start afresh on application on applicationDidBecomeActive.
I am building an iPhone app. Currently when I close the app and relaunch it, it relaunches on the last viewed view. Instead I want to be able to reinitialize the app, and present the view that's most appropriate for the application's state (based on what's in the database).
How can I do that?
You have two options. You can follow Petesh's suggestion to make your app always terminate, or you can implement -applicationWillEnterForeground in your app delegate and reset things there.
I presume it's iOS4 - your app is not being terminated in this case, it is merely being suspended.
You need to follow the instructions here: http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-apps-exit-for-real/ which will terminate the app when the user presses the home button.
You need to add the appropriate 'correct view' logic to your application's start-up code once you've done this.
For the purposes of expediency, I'm adding the instructions here:
Open your info.plist file
Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
Set the new key to YES or Fill in the tick box
Today i updated my 3GS i-phone to install my application to see it's functioning well in OS4,when i'm running the application and tap the home button it's goes to multitasking bar,then again i get the application from there it's goes to previous state where i was.i think the behavior is OK. but problem comes when i kill the application in multitasking bar and run it it's come to same state,simply it's ignore the login screen.
My question is when i kill the application i want to get my login screen, not the previous state, this application is working fine in 3GS,can some one please help me to fix this issue?
Thanks
Sam.
Sam,
If you don't want the OS to save state for you, you should place the key UIApplicationExitsOnSuspend in your info.plist file.
More information here: http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
This will kill the app when the home button is pressed, instead of suspending it into the background (which is what iOS4 does for multi-tasking).
My app crash on exit after upgrade to sdk 4, the error is bad memory access.
I figured that if I put "exit(0)" in "applicationDidEnterBackground:(UIApplication *)application", the app would exit normally.
However, is this ok? This is my only "solution" to the problem so far.
NSZombie is not too helpful this time...
If there's a bad memory access issue, I think the best solution should be to find and fix the memory issue.
However, if you want to stick to the "prevent entering background" way, you should use the appropriate method : disable multitasking. It is described here.
If you do not want your application to remain in the background when it is quit, 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
Do not put exit(0) in applicationDidEnterBackground:(UIApplication *)application.
Instead, add a key to your Info.plist file to flag that you want the application to exit when it is suspended. For details look at Property List Options.
I find the source of the problem. The problem is that I need to perform all task that affect the interface or views on the main thread. Figuring out this also solved a multiply other bugs that give me headcase. It seems that iOS 4 is more restrictive on thread usage