本地服务或远程服务

本地服务或远程服务

本文介绍了本地服务或远程服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须长期运行后台服务。该服务只是要我的活动互动。

  1. 我如何检查活动的简历,如果该服务仍在运行?难道还有比在服务类中的静态变量更好的可能性?

  2. 是它的优势,在一个单独的进程使用远程服务(延长工作寿命时间),以便当活动过程中被打死的服务还活着?

解决方案

这是不可能的。用户或Android会杀了你的服务在一些点。请重新考虑你的架构。

通常情况下,你不知道。

如果用户或Android杀死了你的服务,将无法正常工作。

一个远程服务无关的服务是否运行活动被摧毁后。如果你调用 startService(),运行服务,独立于任何活动,直到:

I have a background Service which must run permanently. The service just has to interact with my Activity.

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

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

这篇关于本地服务或远程服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:31