16

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

Blaise
  • 13,139
  • 9
  • 69
  • 97
michel.iamit
  • 5,788
  • 9
  • 55
  • 74
  • @AustinAllover : I Don't think I understand your question, or you my problem. The cordova (phonegap) app is killed by android (because of memory issue) in this case there is no callback. After the picture is taken, the phonegap app is restarted from scratch... no knowledge of anything happened before this.... – michel.iamit Nov 28 '13 at 19:33
  • 1
    this question has some interesting answers... http://stackoverflow.com/questions/8368091/phonegap-camera-restarts-the-application –  Nov 28 '13 at 19:38
  • Thanks, pretty usefull.... although the highest rating goes to the plugin mentioned in my question (which supports until phonegap 2.4.0) This option might be usefull: but only while testing as a developer: "Developer options" called "Don't keep activities". – michel.iamit Nov 28 '13 at 20:00
  • The best solution, as today, is to develop a custom camera plugin for Android/Cordova. If you want a ready solution see the comment of AustinAllover. – lifeisfoo Aug 26 '15 at 14:20

2 Answers2

1

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.

Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
  • Thanks for your answer. The real solution would probably have to come from android developers... if they just would check which process had started the camera before killing to free memorry.... Not working on this project right now, as you stated, not possible to give a real answer. But you give some good indications about amounts. – michel.iamit Sep 29 '15 at 11:32
1

Try to find a plugin that do not launch the system camera app. Instead use a custom camera activity with only limited features to reduce memory usage.

Khawar Raza
  • 15,870
  • 24
  • 70
  • 127