- Home /
How to prevent Android from killing my Unity app ?
Hi. I'm developing an augmented reality app where users can shoot a photo with their mobile device to add 3D objects on it. The problem is that on Android, when the user choose to shoot a photo from my app, the app is put on the background and often closed instead of being kept in memory to handle the photo taken. I know it is because of Android killing apps to free ram.. But is there a way to prevent the killing of my app ? Even on Ipad 2 with its 512Mo of ram IOS doesn't do this brutal killing thing : after the shooting it goes back smoothly to the app. Whereas Android does it with my 1Go of ram phone.
On the phone settings under "Developer Options" there's an "Apps" section with the checkbox "Do not keep activities". That's not checked by chance?
No. And I tried to change the limit from standard to 4 running process, and it's not working better. I wonder if I ran my Unity app as a service it would be less likely to be killed.
Did you run "adb logcat" and check if the app simply crashes when backgrounded? The logcat should have an entry if it crashes or system closed it, otherwise app exiting on its own.
Well the app doesn't crash the system kills it to free memory : it's in the logcat and also more my app takes ram more it is likely it is killed by Android when I shoot a picture
Answer by venusboysatish · Oct 03, 2013 at 05:16 PM
The only way to stop android from killing your apps is to reduce the memory footprint of your game. I don't believe you can override this core android behavior. If the app takes up more than 50 MB (roughly) , android will kill it when paused. use the profiler to see if you are crossing that limit. If you do cross 50 MB, one simple way of avoiding the high memory usage is to load and unload texture data of your assets dynamically. this will require some coding. Look up Resources.Load and Resources.UnloadAsset functions. make sure you do the loading and unloading of assets in couroutine functions.
Thanks for your answer. So I assume if I run my app on a 2Go ram tablet the process will be killed too ? (it surely uses more than 50$$anonymous$$B of ram sometimes) I find that 50$$anonymous$$B limit weird : new phones are getting more and more ram and can handle pretty heavy ressource consu$$anonymous$$g apps.. sad that multitasking is so limited. They should consider to add a swap partition on Android phones with a lot of drive memory.
i am not too sure about the 50 $$anonymous$$B limit and how it behaves on a phone with 2 gb ram. its just that in my experience of making 2 games, when tested on android devices with 512 $$anonymous$$B ram, our games were getting killed if the memory consumption is little over 55 $$anonymous$$B, we managed to reduce that to 45 $$anonymous$$B, and the games were not getting killed. i strongly suggest you use the afore mentioned functions to trade cpu power for memory foot print.
Your answer
Follow this Question
Related Questions
Export & Install APK on Android 5 Answers
Read Phone Info From Editor? 0 Answers
Bugsense in unity(android) 1 Answer
Unable to merge android manifests Google Play Games Services 23 Answers
Minimum Api 19 not shown for Android 1 Answer