问题描述
我有一个必须长期运行后台服务。该服务只是要我的活动互动。
-
我如何检查活动的简历,如果该服务仍在运行?难道还有比在服务类中的静态变量更好的可能性?
-
是它的优势,在一个单独的进程使用远程服务(延长工作寿命时间),以便当活动过程中被打死的服务还活着?
这是不可能的一>。用户或Android会杀了你的服务在一些点。请重新考虑你的架构。
通常情况下,你不知道。
如果用户或Android杀死了你的服务,将无法正常工作。
一个远程服务无关的服务是否运行活动被摧毁后。如果你调用 startService()
,运行服务,独立于任何活动,直到:
- 您拨打
stopService()
从活动 - 的服务呼叫
stopSelf()
- 的Android终止服务
- 在用户终止通过设置应用程序 服务
- 用户通过一个任务杀手终止服务(的Android 2.1和更早的版本,至少)
I have a background Service which must run permanently. The service just has to interact with my Activity.
How to i check on activity resume if the service is still running? Is there a better possibility than a static variable in the service class?
Is it of advantage to use a remote service in a separate process(to extend service life time) so that when the activity process gets killed the service is still alive?
This is not possible. The user or Android will kill off your service at some point. Please reconsider your architecture.
Generally, you don't.
That will not work if the user or Android kills off your service.
A remote service has nothing to do with whether the service runs after activities are destroyed. If you call startService()
, the service will run, independent of any activities, until:
- you call
stopService()
from an activity - the service calls
stopSelf()
- Android terminates the service
- the user terminates the service via the Settings application
- the user terminates the service via a "task killer" (Android 2.1 and earlier, at least)
这篇关于本地服务或远程服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!