我有一个PhoneGap的应用程序,其功能是为特定人群的通信服务。使用上的PhoneGap,插件GitHub的页面,我已经实现通知到应用程序中发现的本地通知插件,以便每当有人收到一封新邮件,通知就会出现,如果应用程序是在后台。
I have a Phonegap app that functions as a communication service for a specific group of people. Using the local notification plugin found on the phonegap-plugins GitHub page, I have implemented notifications into the app, so that whenever someone receives a new message, a notification will appear if the app is in the background.
大约一小时后,虽然不会产生更多的通知,看来这个过程被打死。当我返回到应用程序,它开始的完全结束,而不是从我上次离开恢复。我假设了一定时间后,机器人停在后台运行的应用程序。
After about an hour, though, no more notifications will occur, and it appears the process was killed. When I go back into the app, it starts completely over instead of resuming from where I last left off. I'm assuming that after a certain amount of time, Android stopped running the app in the background.
有谁知道如何保持应用程序在后台运行,直到它被用户告知停止,和prevent的Android杀死进程?
Does anyone know how to keep the app running in the background until it is told by the user to stop, and prevent Android from killing the process?
推荐答案
由于CommonsWare建议,你可以写一个虚拟的服务,让您的应用程序还活着,而且还因为他正确地指出,如果你打算去努力写一个本地的虚拟服务,你可能也写本地实际的服务,并用它做。
As CommonsWare suggests, you could write a dummy service to keep your app alive, but also as he rightly suggests, if you're going to go to the effort of writing a native dummy service, you may as well write the actual service natively and have done with it.
作为一个位的快速和肮脏的解决方案,你也许可以使用部分wakelock(的看到这里),以确保CPU上运行你的应用程序,而它在后台运行。
As a bit of a quick and dirty solution, you could maybe use a partial wakelock (see here) to keep the CPU running your app while it's in the background.
我成功地用这种方法来保持我的 PhoneGap的基础散步导航应用活着的背景,使他们能够继续接收和处理位置更新。
I successfully used this approach to keep my Phonegap-based walk navigation apps alive in the background so they can continue to receive and process position updates.
在你的情况,活着接收通知不完全是一个局部wakelock的目的是为等我不确定机器人是否会杀了你的应用程序后,反正一段时间,因为它没有做任何事情(不像我的是不断接收和处理位置更新),但它可能做的工作,而不需要写一个服务,因此可能是值得一试。
In your case, staying alive to receive notifications isn't exactly what a partial wakelock was intended for and so I'm unsure whether android will kill your app anyway after a while since it's not doing anything (unlike mine which is constantly receiving and processing position updates) but it might do the job without needing to write a service, so may be worth a try.
有一个在我的answer这个问题其中包含我的code代表的电源管理选项的插件为Android 。我更新了插件的使用与科尔多瓦2.8.0而且还扩展到能够获得部分wakelock。
Have a look at my answer to this question which contains my code for an updated version of the PowerManagement plugin for Android. I updated the plugin for use with Cordova 2.8.0 but also extended it to be able to acquire a partial wakelock.
相关推荐
最新文章