Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android causes Cordova apps to restart when using Cordova Camera and Capture plugins

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.

like image 857
mpsyp Avatar asked Jun 25 '14 00:06

mpsyp


1 Answers

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

like image 117
Pablo W. Avatar answered Oct 19 '22 11:10

Pablo W.