Phonegap Android应用程序后台CPU使用情况
我一直在为 Android 开发一个phonegap应用程序,但我坚持以下几点;当我将应用程序置于后台并检查任务管理器时,该应用程序仍然消耗大量 CPU(5% 之间,有时甚至达到 15%)。我尝试删除代码的所有其他部分,但阻止应用程序在后台进行 CPU 活动的唯一方法是从代码中删除phonegap.js。
我的印象是 Phonegap 在进入 onPause 时会停止 javascript 执行,但我一定错过了一些东西。
我已经尝试过 1.1.0、1.2.0 和 1.1.0。 1.3.0没用。同样有趣的是,如果我使用phonegap启动2个应用程序,它们的后台CPU使用率似乎表现相同:一个上升,另一个上升,并且大多数情况下它们的使用率精确到百分比。
有谁知道应用程序仍在 CPU 中做什么和/或我如何找到答案?
问候
I have been doing a phonegap app for android but am stuck on the following; When I background the app and check the task magager, the app still consumes a considerable amount of CPU (between 5% and sometimes even to 15%). I have tried removing all other parts of my code but the only thing that stops the app from having CPU activity in the background is removing the phonegap.js from my code.
I was under the impression that Phonegap would halt javascript execution when going into onPause but I must be missing something.
I have tried 1.1.0, 1.2.0 & 1.3.0 to no avail. Interesting too is that if I fire up 2 apps with phonegap, their background CPU usage seem to behave the same: One goes up, the other goes up and mostly they are exact in usage up to the percentage point.
Has anyone got any idea what the app is still doing in CPU and/or how I could find out ?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当应用程序进入 onPause 时,js 执行不会停止,它仅在应用程序关闭/终止时停止。
the js execution is not halted when the app goes into onPause, it only halts when the app is closed/killed.
Cordova/PhoneGaps 默认行为是让应用程序在后台运行,您可以通过在 config.xml 中添加“keepRunning”标签来更改它:
keepRunning(布尔值,默认为 true) -
确定 Cordova 是否继续在后台运行
Cordova/PhoneGaps default behaivior is to keep the app running in background, you can change that by adding a "keepRunning" tag to your config.xml:
keepRunning (boolean, defaults to true) -
Determines whether Cordova will keep running in the background or not
我注意到同样的问题,尤其是在 KitKat 上。要解决此问题,在您的主活动(扩展 DroidGap 的活动)中,您需要为您的 WebView(即“appView”变量)调用 onPause() 方法。
这会暂停与 WebView 相关的任何额外处理,这应该会显着减少 CPU 使用率:
I noticed the same problem, especially on KitKat. To resolve the issue, in your main activity (the activity which extends DroidGap), you need to call the onPause() method for your WebView (which is the 'appView' variable).
This pauses any extra processing associated with the WebView which should reduce your CPU usage significantly: