开发者

Why does my program crash when I restart it after removal from the recent-apps bar?

I'm a bit of a programming newbie so sorry if this shows my ignorance...

Situation 1:

  • My program is running in the simulator. I press the home button, and then my program's icon again, and it goes back to exactly where it was. This much is obvious - it's been frozen by the iPhone's multitasking system.

Situation 2:

  • My program is running in the simulator. I press the home button, but this time I then double-click the program and delete it from the recent-apps bar. Then I press the program's icon to start it again.

In situation 2, I expect my program just to load from the beginning, but instead, it goes back to the page it was 'frozen' on, briefly, before crashing.

Why is this?

EDIT - here is the backtrace of the crash. I've done it with a completely clean install of my app with no data, from the first screen you see, to keep variables to a minimum:

#0  0x96dc009a in mach_msg_trap ()
#1  0x96dc0807 in mach_msg ()
#2  0x0111cd86 in __CFRunLoopServiceMachPort ()
#3  0x01079e74 in __CFRunLoopRun ()
#4  0x01079840 in CFRunLoopRunSpecific ()
#5  0x01079761 in CFRunLoopRunInMode ()
#6  0x01c821c4开发者_如何学Go in GSEventRunModal ()
#7  0x01c82289 in GSEventRun ()
#8  0x001c4c93 in UIApplicationMain ()
#9  0x00002429 in main (argc=1, argv=0xbffff050) at main.m:14


Copied from comment because this theory appears to have been correct: Are you running through the Xcode debugger? It could be that when you kill the app, the debugger sort of prevents the process from being completely destroyed, causing the crash on the subsequent launch. Apparently it work correctly if you initially launch the app from the simulator instead of via Xcode's debugger.


When your app is terminated from the App Switcher, it calls your app delegate's applicationDidEnterBackground:(UIApplication *)application method. Here you should save all application state–all of the memory your app uses will be released. What's likely happening is either that something in your applicationDidEnterBackground: method is crashing or something in the mass deallocating of your object model is causing a crash.

edit:

I just reread your question and saw that it's crashing on relaunch. Sorry. You should also check application:didFinishLaunchingWithOptions: for a crash, as that is called when your app first starts. Although since you're seeing the last screen before the app was closed, the crash still seems like it may be tied to terminatation.

How to get a backtrace:

If you run the code in the simulator with debugging on in Xcode and reproduce this crash, you should be able to discover which line is crashing. When the debugger picks up on the crash and gdb turns on (you should see a (gdb) prompt in Xcode), type bt and press enter to see the backtrace of the crash. Paste it here.

See the docs of UIApplicationDelegate for more info on applicationWillTerminate:.


I had same problem. For some reason the simulator prevents us to kill the app we are testing. One thing I did for testing was to create a dummy project to If you launch the simulator from another dummy project. Then I could open/close/kill test notifications, etc in my original project.


Unplug the phone, yes. GDB, the debugger, is the cause of this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜