Phonegap摄像头android杀死了科尔多瓦 [英] Phonegap camera android kills cordova

查看:19
本文介绍了Phonegap摄像头android杀死了科尔多瓦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事多个 Phonegap 项目.在其中一些中,我使用了相机功能.

I'm working on several Phonegap projects. In some of them I'm using the camera functions.

我对这个问题感到困惑(来自 Phonegap 文档):

I'm puzzling with this issue (from the Phonegap documentation):

Android 怪癖

Android 使用 Intent 在设备上启动相机 Activity捕获图像,在内存不足的手机上,Cordova 活动可能会被杀死.在这种情况下,图像可能不会出现在科尔多瓦活动已恢复.

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.

我在我的一台测试设备(HTC One X)上经常遇到这个问题.挺满的,好好测试一下.

I'm having this problem on one of my test devices constantly (HTC One X). It's quite full, so good to test this.

我注意到有一个替代插件:https://code.google.com/p/foreground-camera-plugin/ 解决这个问题.但我尽量避免使用插件......(轻松移植到其他平台).它适用于 Phonegap 2.4.0,我正在使用 Phonegap 2.9.0

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

我已经使用了文件 URI 而不是数据(以避免内存问题).

I already use the file URI and not the Data (to avoid the memory problem).

我的问题是:有人知道 Android 何时决定终止其他活动(例如 Cordova,Phonegap 非常需要).在什么级别的空闲内存?(百分比,MB).所以我可以提前检查并警告用户.

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

在第一条评论后编辑

我无意解决真正的问题,我发现这不太可能.这是Android和Phonegap之间的事情.我只需要知道是否可以警告用户这会发生.所以用户可以在继续之前杀死其他一些应用程序......那么这什么时候会发生?android什么时候认为没有足够的内存来让这件事发生?这是我的问题.

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.

2013 年 11 月 29 日编辑

由于 AustinAllover 提供的链接,我现在知道这不仅仅是一个 Phonegap 问题...... Android 相机似乎会在内存太少的情况下杀死所有 Java 应用......所以这个问题比 Phonegap 更通用/仅限科尔多瓦...

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

推荐答案

不确定您的问题是否有好的答案,但我会尝试.

Not sure if there exists a good answer to your question but I will try.

当应用程序被杀死以释放内存时,这取决于很多因素.第一个也是主要的因素是相机活动需要运行多少.相机应用程序本身在大多数设备上(尽管有所不同)大约 10MB.这是应用程序在内存中的大小,而不是运行活动时所需的大小,这在逻辑上会更大一些.它还取决于相机本身和存储实际照片所需的内存量,假设存储时照片约为 4MB,原始照片约为 20MB.这为我们提供了应用运行的近似上限 30MB,但这是推测,我稍后会自己检查并编辑它.

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.

您可以在此处找到有关与 Android 相关的内存的良好参考 https://01.org/android-ia/user-guides/android-memory-tuning-android-5.0-and-5.1他们建议始终有 500MB 或更多内存可用于运行应用程序,这当然适用于您正在运行的所有应用程序,而不是针对某个特定应用程序.

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.

比 GC 开始从内存中删除应用程序的点,这发生在非常接近内存的实际边界时,当少于 5% 仍然可用时,这个值是我自己实验的经验值.首先,它会杀死仍在缓存中但不再需要的应用程序,只有作为最后的手段,它才会杀死也处于活动状态的应用程序.

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.

我的假设是,您的应用将在大约 50MB 的可用内存以下被杀死,但我必须强调,这里有很多假设,并且没有通用的方法可以告诉您针对每种设备和每种相机的正确答案以及各个版本的 Android.

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.

希望有帮助,怕没用.

这篇关于Phonegap摄像头android杀死了科尔多瓦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆