9

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.

4

5 回答 5

4

phonegap 相机 API 在您使用时调用相机应用程序

navigator.camera.getPicture

请在此处阅读 - http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html#Camera

这会将您的应用程序推到后台,如果内存不足,可能会导致您的应用程序被终止。

如果您不希望您的应用程序在摄像头启动时进入后台,您需要使用前景摄像头插件。看看这里

您可能需要更改它以满足您的要求。

于 2013-11-11T06:21:43.613 回答
1

您不需要创建一个完整的自定义前景摄像头,您只需向积极的垃圾收集器指定您想要检索旧意图而不是启动新实例。尝试在相机插件中为保存的意图设置一个标志:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

在这里查看我的帖子:https ://stackoverflow.com/a/29630548/2782404

此外,增加堆大小和使用 singleTask/singleInstance 对我不起作用

于 2015-04-14T14:57:37.360 回答
1

这可能是与内存相关的问题。您可以通过 android:largeHeap="true" 在应用程序清单文件中进行设置来增加应用程序的堆大小。

于 2013-11-06T02:12:10.340 回答
0

看到这个链接,它解释说这实际上与phonegap无关,而是与android的活动有关。他建议使用一个名为 Foreground Camera Plugin 的插件。

PhoneGap 摄像头重启应用

于 2014-12-10T13:24:28.637 回答
0

在 android 清单文件中,将活动的启动模式设置为“singleTask”或“singleInstance”。
可能是您的应用程序多次启动该活动。

于 2013-11-11T12:45:01.973 回答