tags:

views:

278

answers:

3

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...

+5  A: 

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

David
David is right, you should not do that. Apple Human Interface Guidelines will tell you that's wrong.
Pierre Valade
Agreed. Don't treat the symptom, but find the source of the problem.
Brad Larson
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
Mak Sing
+1  A: 

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.

xmr
It is werid, I tried add the property but it doesn't seem to do anything... The function applicationDidEnterBackground is still being called and I still get the error.. maybe I missed something.
Mak Sing
A: 

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

Mak Sing