I am developing phonegap app. And using camera in it. It was working few days ago. I did many changes in last few days and now camera is not working correctly. It opens camera but when I take photo , then from camera app. when I press OK, it restart app.
I am not understanding how it is doing so. I actually unable to understand whether it can restart from my phonegap app. JS code or it only can be restart from android Java code.
I am using this code for camera:
function takePhoto() {
navigator.camera.getPicture(onCameraPicSuccess, onCameraPicFail, {quality: 50,
destinationType: Camera.DestinationType.FILE_URI
});
function onCameraPicSuccess(imageURI) {
alert("coming here in pic success");
var img = '<div style="padding:4px; margin:10px; border: solid 2px #666;float: left; width:30%"><img src="' + imageURI + '" width="100%" /></div>';
$('#images_area').append(img);
}
function onCameraPicFail(message) {
alert('Failed because: ' + message);
}
So any idea, that why app. will restart on using camera app. through above code? My JS code don't have splash screen but my Java code have that. So after pressing OK button of camera, I can see app. restarted with back button
binding and menu button
binding not working for a while.
So not sure what is happening. If you guys have any such experience or any idea then feel free to share.
If there is some thing more I need to tell. Then let me know.
After doing some more search on stackoverflow.com, I came to know that issue is of android, as android kill the app. in background if it have less memory. So need to free the memory e.t.c. But what I noticed is that application was working fine when I was using JQuery Mobile Forms. But after I changed it to custom, this camera problem appear. So if this is memory related problem, then why it occured on removing jquery mobile forms and doing custom work. In fact, now application is even more smooth with custom work. So I am confused that whether it is memory related problem or something else? And how to tackle this type of app. developed in phonegap.
The phonegap camera API invokes the camera application when you use
navigator.camera.getPicture
Please read it here - http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html#Camera
This pushes your application into the background and that can lead to your app being killed if there isn't enough memory.
If you don't want your application to go into background while the camera is up, you need to use a foreground camera plugin. Take a look at it here
You might need to change it to suit your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With