10

It appears that there is a common failure that happens when Cordova apps are put in the background to use the Camera or Media Capture plugins... the Android activity service appears to look for memory to free up and kills the Cordova activity, so that when the user completes the capture task the app RESTARTS. See SO thread here:

PhoneGap camera restarts the application

This is a total UX fail and would very likely prevent me from releasing my Cordova app. People don't take kindly to their photos getting lost. I am using Cordova 3.3 and a somewhat older version of the Capture plugin as an upgrade a month ago caused breaking changes and I rolled back. Anyway, it appears that at some point someone created a custom plugin called foreground camera that never allowed the app to go into onStop state, which fixed the problem:

https://code.google.com/p/foreground-camera-plugin/

Unfortunately, this custom plugin is horribly out of date (Cordova 2.4). Is it possible for the native Cordova plugins to be modified to prevent this terrible restart behavior? Are there any plans to doing so? Or is it only possible by creating a completely new camera plug-in, from scratch, one that doesn't use the native camera application?

I have posted to the Cordova dev list but no response yet. Any thoughts on how best to resolve this situation are appreciated.

Thanks.

Community
  • 1
  • 1
mpsyp
  • 472
  • 3
  • 17
  • I have had fewer problems with this lately. I'm not sure ultimately what is helping, but I followed some advice elsewhere to uninstall 3rd-party camera apps and restart my device. I did happen to have a few apps I wasn't using (specifically VSCO and one other), and it seems to have done the trick. Ultimately, this is not a great solution, but in the meantime, at least app crashes are not killing my demos. – mpsyp Oct 01 '14 at 16:39
  • Did any one find a solution? – Emad Emami May 18 '16 at 06:01

3 Answers3

1

Implementing a proper app lifecycle seems to be the recommended way to workaround this issue:

http://cordova.apache.org/docs/en/dev/guide/platforms/android/index.html#what-makes-android-different

Pablo W.
  • 76
  • 2
0

You might be able to use the same camera plugin with your app. Try to reduce RAM consumption as much as possible, prior to plugin start.

  • Remove hidden DOM nodes
  • Free JavaScript RAM by deleting unused objects/instances

We had this issues on Android 2.3 phones with little RAM. Freeing all possible RAM finally fixed the problem. The app was paused while taking a photo, not killed and restarted.

Mario
  • 8,253
  • 2
  • 14
  • 29
0

I checked several posts with the same question. Tried everything until i found this:

changing button tags for anchor tags in html for the event that calls the camera: change

<button data-icon="camera" id="btn-get-image">Capturar Imagen</a>

for this

<a href="" class="ui-button" data-icon="camera" id="btn-get-image">Capturar Imagen</a>

further can be found here. Cordova app restart after getting picture from capture or photo Librairie