Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap camera android kills cordova

I'm working on several Phonegap projects. In some of them I'm using the camera functions.

I'm puzzling with this issue (from the Phonegap documentation):

Android Quirks

Android uses intents to launch the camera activity on the device to capture images, and on phones with low memory, the Cordova activity may be killed. In this scenario, the image may not appear when the cordova activity is restored.

I'm having this problem on one of my test devices constantly (HTC One X). It's quite full, so good to test this.

I noticed there is an alternative plugin: https://code.google.com/p/foreground-camera-plugin/ for this problem. But I try to avoid plugins as much as possible... (to be portable to other platforms easily). And it's available up to Phonegap 2.4.0 and I'm working with Phonegap 2.9.0

I already use the file URI and not the Data (to avoid the memory problem).

My question is: does anybody know when Android decides to kill other activities (like Cordova, which is quite needed for Phonegap). On what level of free memory? (percentage, MB). So I could check this in advance and warn the user.

Of course I hope this issue gets resolved... but it doesn't seem to be resolved soon....

Edit after the first remark

I've no intention resolving the real problem, I've found out that's not really possible. It's a thing between Android and Phonegap. I just need to know whether it's possible to warn the user this will happen. So the user can kill some of the other apps before continuing... So when does this occur? When does android think there is not enough memory to get this thing going on? That's my question.

Edit 2013 Nov. 29th

Because of the link given by AustinAllover, I now know this is not just a Phonegap issue... The Android camera seems to kill all Java apps in case of too few memory... so the question is more generic than Phonegap/Cordova only...

like image 347
michel.iamit Avatar asked Nov 28 '13 19:11

michel.iamit


1 Answers

Not sure if there exists a good answer to your question but I will try.

It depends on quite a few factors when apps get killed to free memory. First and major factor is how much the camera activity needs to run. The camera app itself is on most devices (though it varies) around 10MB. This is the size of the app in memory and not the size it takes when running the activity, which would be logically a bit bigger. It also depends on the camera itself and the amount of memory needed to store the actual photo, lets assume the photo is around 4MB when stored, and raw around 20MB. This gives us an approximate upper limit of 30MB for the app running, though is speculation and I will check this myself later and edit it.

A good reference about memory related to Android you can find here https://01.org/android-ia/user-guides/android-memory-tuning-android-5.0-and-5.1 They advice to always have 500MB or more memory available to run apps, this is of course for all apps you are running and not for one specific app.

Than the point that GC starts removing apps from memory, this happens very close to the actual bounds of the memory, when less than 5% is still free, this value is emperical by my own experiments. First it kills apps that are still in cache but not longer required, only as last resort it kills apps that are active as well.

My assumption is that your app will be killed below approximately 50MB of memory free, though I have to stress that there are many assumptions here and there is no general way to tell you a good answer for each device with each kind of camera and each version of Android.

Hope it helps, fear it does not.

like image 110
Bas van Stein Avatar answered Sep 28 '22 03:09

Bas van Stein