Android平台PhoneGap的应用程序 - 让应用程序运行 [英] Phonegap app on Android platform - keep app running

查看:204
本文介绍了Android平台PhoneGap的应用程序 - 让应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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的Andr​​oid杀死进程?

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.

有一个在我的<一个href="http://stackoverflow.com/questions/17250808/plugin-phonegap-power-management/17251197#17251197">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.

这篇关于Android平台PhoneGap的应用程序 - 让应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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