I have a map based and location based app which I put into the background. I then start a a game app (agent dash) after the game app has finished initializing I noticed that my app has been killed: 9 in the device log. Sometimes I get a memory warning message, sometimes not. But is it possible for one app to cause another to be terminated. If I run the my app on its own there is no problem. I run other apps in the foreground and no problem. Also if an app can cause mine to be terminated can I generate a restart? Thanks
Agent dash must be an memory intensive app, so when the iOS feels its running out of memory it generates memory warnings which each app needs to handle. It can even kill your app if it needs more memory. The primary thing iOS takes into consideration is that it wants to keep the app which the user is using alive. And no you can't restart your app pro grammatically the user will have to do it if he wants to.
Related
I am facing very strange problem in my app. My app is getting killed when I keep my app in background for long time. I have checked the memory usage of the app in the 'instruments' tool, the live memory usage of the app was 1.48mb and overall usage was 6.18mb, which is not very high. Still my is getting killed.
I have checked my app even if there are few apps running in background say around 4 still it's killing my app. What might be the reason for this?
When I press the home button my app is suspended correctly, however it only lasts a few minutes. If I leave it for a short while and return to it the app starts up fresh.
I'm not running any background tasks in my app and other apps stay suspended for much, much longer than mine.
What could be the potential causes of this? Is it likely I have operations running in the background that I'm not aware of and iOS is killing my app when it is short on memory?
The apps that are using the most memory are terminated first in the background. So the likely cause is that your app is consuming more memory than you think it is. I'd start with ensuring that your memory is being managed correctly.
Apple - App States and Multitasking
While the device is powered on, is it possible for iOS to automatically terminate my app (calling applicationWillTerminate:) while it's in the background?
I'm also curious what happens in two other cases, three in total:
Device is powered on
Device is powered off
Device loses battery
I'm asking because I want to know how often applicationWillTerminate: is likely to get called. I want to know this because that's where I'm registering for remote notifications. And if there's a failure sending the device token to the server, I want to know how likely it is that that method will get called again (i.e., retry sending the device token to the server).
If your application supports multitasking (the default for anything linked against iOS 4.0+), this method will almost never be called. The documentation says it may be called in cases where the application is running in the background and the system wants to terminate. However, in my experience, I've only ever seen this actually called when running a music app that's actively playing music in the background and the system is jettisoning everything. In cases where I have background tasks running (not music, but short-term background tasks), I've seen the app terminated without this method being called.
I wouldn't ever rely on this being called and try and do all the clean-up you need to do in your delegate methods for transitioning into the background and your background task completion blocks (which do get executed for at least a few seconds before the app gets jettisoned).
Not only can iOS terminate your app automatically, but the user can kill it manually. In fact, the only time the user can kill your app is when it's in the background. Furthermore, when your app is "in the background" it's more likely to be suspended than actually running, so don't count on doing a lot of processing when you're not the foreground app.
As for how likely it is that you'll get -applicationWillTerminate:, that'll depend on the user and how they're using their device. You should handle it appropriately when you get it, and go about your business otherwise.
When memory is running low, iOS can shut down your app, calling applicationWillTerminate.
The docs say this about the method:
... However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.
Check out iOS Developer Library : iOS App Programming Guide : App Termination.
I am facing a weird problem. My iPhone app is password protected and only after entering the correct password, can the user be logged in again. Also the app has multiple screens.
Suppose I am on a particular screen(after logging in) and switch off the device(with app still running), switch on the device back and launch my application, it starts back from the screen which was visible when the device was restarted. The password screen is not shown, and it seems like applicationDidFinishLaunching was never called. When I kill the app from background and start it again, it works normal.
Wouldn't the app loose all data in memory when the device is restarted? Wouldn't the views will have to be drawn again? How exactly does an app behave in this case.
EDIT:
I did what TriPhoenix has suggested. What I observed is that if you switch on the device and launch the application very soon, the applicationDidBecomeActive delegate method doesn't get called. However if you give it some time before launching, everything seems to work as expected. Isn't the applicationDidBecomeActive method supposed to be called with every app launch?
What I am testing on:
OS: iOS 5.0.1
Xcode: 4.2.1
Device: iPhone 4s
Is it possible that your app is very small in terms of memory usage? I remember a WWDC talk (cannot find the right one right now unfortunaly) where it is told that very small apps in terms of memory usage (a limit is not publicly defined but I think it was around 16 MiB memory usage) are not killed on low memory conditions but rather suspended to the phone's flash memory to be awakened later. I'm not sure if this is designed to survive a complete shutdown but it would sure be one of the few possibilities. To check this you could try to artificially increase your memory usage by creating some large objects / arrays and see if the problem disappears.
In any case there might be better functions to reactivate the password protection, e.g. applicationWillEnterForeground: or applicationDidBecomeActive: as this should cover all possibilities where the user might return to your app.
Saw an app called PhoneRecover on the AppStore.
They advertise the following:
PhoneRecover will automatically restart after a reboot on the iPhone 3GS and the iPhone 4 running iOS4.
How is this possible? What APIs are used to auto-launch an app after a boot?
It's built into multi-tasking. "Backgrounded" apps are still in background after a reboot. Presumably the app does some work to re-instantiate itself and get its state going again the first time Core Location hits it in the background, but there's no other magic happening here. Any background-aware app will survive a reboot in a backgrounded state.
I wouldn't count on this. I was running MotionX GPS and let the battery run completely dead. Upon restart MotionX was no longer running, broadcasting my position or tracking my position. The broadcast option is persistent too (survives app restart).