美文网首页
Android Service 绑定的几种模式

Android Service 绑定的几种模式

作者: b7cda9616c52 | 来源:发表于2017-05-09 09:43 被阅读161次

绑定服务的方式前面已经写过了,就不再写了,这里主要研究下绑定的几种模式。

BIND_AUTO_CREATE

绑定的时候若服务未创建则会自动创建服务,不会回调 [onStartCommand(Intent, int, int)](https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent, int, int)) 方法,只要绑定上了,就可以与服务进行交互了。

在所有任务完成、以及解除所有绑定的情况下,销毁服务。

BIND_DEBUG_UNBIND

调试的时候使用(没发现怎么使用)。

BIND_NOT_FOREGROUND

不让服务提升优先级,但仍然可保证与所绑定客户端的优先级相同,服务仍然在后台执行。所以一般情况下,绑定服务的客户端存在,系统也就不会杀死服务。

不管服务是否被绑定,哪怕是启动的前台服务,只要任务完成了就销毁服务。

BIND_ABOVE_CLIENT

被绑定服务的重要性高于客户端,当内存不足时,首先释放客户端,再考虑释放服务。

BIND_ALLOW_OOM_MANAGEMENT

allow the process hosting the bound service to go through its normal memory management. It will be treated more like a running service, allowing the system to (temporarily) expunge the process if low on memory or for some other whim it may have, and being more aggressive about making it a candidate to be killed (and restarted) if running for a long time.

不管服务是否被绑定,哪怕是启动的前台服务,只要任务完成了就销毁服务。

BIND_WAIVE_PRIORITY

don't impact the scheduling or memory management priority of the target service's hosting process. Allows the service's process to be managed on the background LRU list just like a regular application process in the background.

不管服务是否被绑定,哪怕是启动的前台服务,只要任务完成了就销毁服务。

BIND_IMPORTANT

服务对客户端是非常重要的,会将服务提升至前台进程优先级,通常情况下,即使客户端是前台优先级,服务最多也只能被提升至可见进程优先级。

BIND_ADJUST_WITH_ACTIVITY

If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user, regardless whether another flag is used to reduce the amount that the client process's overall importance is used to impact it.

相关文章

网友评论

      本文标题:Android Service 绑定的几种模式

      本文链接:https://www.haomeiwen.com/subject/upvdtxtx.html