本文主要是记录关于bindService的用法的翻译和记录。
先看英文介绍

一、关于方法介绍

boolean bindService (Intent service,
ServiceConnection conn,
int flags)

Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when it is created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.

This function will throw SecurityException if you do not have permission to bind to the given service.

Note: this method can not be called from a BroadcastReceiver component. A pattern you can use to communicate from a BroadcastReceiver to a Service is to call startService(Intent) with the arguments containing the command to be sent, with the service calling its stopSelf(int) method when done executing that command. See the API demo App/Service/Service Start Arguments Controller for an illustration of this. It is okay, however, to use this method from a BroadcastReceiver that has been registered with registerReceiver(BroadcastReceiver, IntentFilter), since the lifetime of this BroadcastReceiver is tied to another object (the one that registered it).

翻译:
连接到应用程序服务,如果需要创建它。这定义了应用程序和服务之间的依赖关系。给定的conn将在创建服务对象时接收该服务对象,并告知其是否死机并重新启动。只要调用上下文存在,系统就会认为该服务是必需的。例如,如果此上下文是已停止的活动,则在恢复活动之前,不需要服务继续运行。

如果您没有绑定到给定服务的权限,此函数将抛出SecurityException。

注意:此方法不能从BroadcastReceiver组件调用。可以用来从BroadcastReceiver到服务的通信模式是使用包含要发送的命令的参数调用startService(Intent),在完成执行该命令时,服务调用其stopSelf(int)方法。请参阅API演示应用程序/服务/服务启动参数控制器的插图。但是,从使用registerReceiver(BroadcastReceiver,IntentFilter)注册的BroadcastReceiver中使用此方法是可以的,因为此BroadcastReceiver的生命周期与另一个对象(注册它的对象)绑定。

二、入参介绍

入参主要有3个参数,分别传入Intent,ServiceConnection对象和一个int变量,这里就不在翻译了。

三、第3个参数flags入参介绍

Operation options for the binding. May be 0, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_NOT_FOREGROUND, BIND_ABOVE_CLIENT, BIND_ALLOW_OOM_MANAGEMENT, or BIND_WAIVE_PRIORITY.

BIND_AUTO_CREATE

Added in API level 1
int BIND_AUTO_CREATE
Flag for bindService(Intent, ServiceConnection, int): automatically create the service as long as the binding exists. Note that while this will create the service, its onStartCommand(Intent, int, int) method will still only be called due to an explicit call to startService(Intent). Even without that, though, this still provides you with access to the service object while the service is created.

Note that prior to ICE_CREAM_SANDWICH, not supplying this flag would also impact how important the system consider’s the target service’s process to be. When set, the only way for it to be raised was by binding from a service in which case it will only be important when that activity is in the foreground. Now to achieve this behavior you must explicitly supply the new flag BIND_ADJUST_WITH_ACTIVITY. For compatibility, old applications that don’t specify BIND_AUTO_CREATE will automatically have the flags BIND_WAIVE_PRIORITY and BIND_ADJUST_WITH_ACTIVITY set for them in order to achieve the same result.

Constant Value: 1 (0x00000001)

翻译:用于bindService的标志(Intent,ServiceConnection,int):只要存在绑定,就自动创建服务。注意,虽然这将创建服务,它的onStartCommand(Intent,int,int)方法将仍然只被调用由于显式调用startService(Intent)。即使没有这个,虽然,这仍然提供您在服务创建时访问服务对象。

请注意,在ICE_CREAM_SANDWICH之前,不提供此标志也将影响系统考虑目标服务进程的重要性。当设置时,它提出的唯一方式是通过绑定从服务,在这种情况下,它只会是重要的,当该活动是在前台。现在要实现此行为,必须显式提供新标志BIND_ADJUST_WITH_ACTIVITY。为了兼容性,未指定BIND_AUTO_CREATE的旧应用程序将自动为它们设置标志BIND_WAIVE_PRIORITY和BIND_ADJUST_WITH_ACTIVITY,以便实现相同的结果。

常数值:1(0x00000001)

BIND_DEBUG_UNBIND

Added in API level 1
int BIND_DEBUG_UNBIND
Flag for bindService(Intent, ServiceConnection, int): include debugging help for mismatched calls to unbind. When this flag is set, the callstack of the following unbindService(ServiceConnection) call is retained, to be printed if a later incorrect unbind call is made. Note that doing this requires retaining information about the binding that was made for the lifetime of the app, resulting in a leak – this should only be used for debugging.

Constant Value: 2 (0x00000002)

翻译:bindService标志(Intent,ServiceConnection,int):包含对unbind调用不匹配的调试帮助。 设置此标志时,将保留以下unbindService(ServiceConnection)调用的调用堆栈,如果稍后发生了不正确的解除绑定调用,则会打印该堆栈。 请注意,这样做需要保留有关应用程序生命周期的绑定的信息,从而导致泄漏 - 这应该只用于调试。

常数值:2(0x00000002)

BIND_NOT_FOREGROUND

Added in API level 8
int BIND_NOT_FOREGROUND
Flag for bindService(Intent, ServiceConnection, int): don’t allow this binding to raise the target service’s process to the foreground scheduling priority. It will still be raised to at least the same memory priority as the client (so that its process will not be killable in any situation where the client is not killable), but for CPU scheduling purposes it may be left in the background. This only has an impact in the situation where the binding client is a foreground process and the target service is in a background process.

Constant Value: 4 (0x00000004)

翻译:bindService的标志(Intent,ServiceConnection,int):不允许此绑定将目标服务的进程提升到前台调度优先级。 它仍然会被提升到至少与客户端相同的内存优先级(以使其进程不会在客户端不可杀死的任何情况下杀死),但是对于CPU调度目的,它可能留在后台。 这仅在绑定客户端是前台进程并且目标服务在后台进程中的情况下具有影响。

常数值:4(0x00000004)

BIND_ABOVE_CLIENT

Added in API level 14
int BIND_ABOVE_CLIENT
Flag for bindService(Intent, ServiceConnection, int): indicates that the client application binding to this service considers the service to be more important than the app itself. When set, the platform will try to have the out of memory killer kill the app before it kills the service it is bound to, though this is not guaranteed to be the case.

Constant Value: 8 (0x00000008)

翻译:
在API级别14中添加
int BIND_ABOVE_CLIENT
bindService的标志(Intent,ServiceConnection,int):表示绑定到此服务的客户端应用程序认为该服务比应用程序本身更重要。 当设置时,平台将尝试使内存杀手杀死应用程序,然后杀死它绑定到的服务,尽管这不能保证是这种情况。

BIND_ALLOW_OOM_MANAGEMENT

Added in API level 14
int BIND_ALLOW_OOM_MANAGEMENT
Flag for bindService(Intent, ServiceConnection, int): 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.

Constant Value: 16 (0x00000010)

翻译:
BIND_ALLOW_OOM_MANAGEMENT

在API级别14中添加
int BIND_ALLOW_OOM_MANAGEMENT
bindService的标志(Intent,ServiceConnection,int):允许承载绑定服务的进程通过其正常的内存管理。 它将更像是一个正在运行的服务,允许系统(暂时)清除过程,如果内存低或一些其他的想法可能有,并更积极的使它成为候选人被杀死(并重新启动)if 运行很长时间。

常数值:16(0x00000010)

BIND_WAIVE_PRIORITY

Added in API level 14
int BIND_WAIVE_PRIORITY
Flag for bindService(Intent, ServiceConnection, int): 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.

Constant Value: 32 (0x00000020)

翻译:
BIND_WAIVE_PRIORITY

在API级别14中添加
int BIND_WAIVE_PRIORITY
bindService的标志(Intent,ServiceConnection,int):不影响目标服务的主机进程的调度或内存管理优先级。 允许在后台LRU列表上管理服务的进程,就像在后台的常规应用程序进程一样。

常数值:32(0x00000020)

Android Service之bindService相关推荐

  1. Android开发Service之BindService

    前言 一直使用 Qt 来进行桌面端和移动端开发,对 Android 开发并不熟悉,但是项目中往往又经常会用到 Android 原生开发的东西.本次收集了一些关于BindService相关的知识供自己学 ...

  2. Android service的两种使用方式bindService和startService使用方式

    服务与多线程的区别: 服务仍然是运行在主线程中,而Thread则是真正的开启了一个新的线程来执行先关操作. 那为什么要用服务呢,初步理解是服务是为了更好地管理线程.试想,当我们在某一个activity ...

  3. Android基础 : Android Service[转]

    2019独角兽企业重金招聘Python工程师标准>>> 很多情况下,一些与用户很少需要产生交互的应用程序,我们一般让它们在后台运行就行了,而且在它们运行期间我们仍然能运行其他的应用. ...

  4. android 浏览器源码分析,从源码出发深入理解 Android Service

    原标题:从源码出发深入理解 Android Service 原文链接: 建议在浏览器上打开,删除了大量代码细节,:) 本文是 Android 系统学习系列文章中的第三章节的内容,介绍了 Android ...

  5. android service 学习(上)

    转载自:http://www.cnblogs.com/allin/archive/2010/05/15/1736458.html Service是android 系统中的一种组件,它跟Activity ...

  6. Android Service完全解析,关于服务你所需知道的一切(下)

    转载请注册出处:http://blog.csdn.net/guolin_blog/article/details/9797169 在上一篇文章中,我们学习了Android Service相关的许多重要 ...

  7. Android Service使用方法--简单音乐播放实例

    Service翻译成中文是服务,熟悉Windows 系统的同学一定很熟悉了.Android里的Service跟Windows里的Service功能差不多,就是一个不可见的进程在后台执行. Androi ...

  8. 关于Android Service真正的完全详解,你需要知道的一切

    转载请注明出处(万分感谢!):  http://blog.csdn.net/javazejian/article/details/52709857  出自[zejian的博客]   Service全部 ...

  9. Android Service详解(二)第一个Service

    Service中有四个重要函数: public IBinder onBind(Intent arg0): //必须实现,返回接口给Servicepublic void onCreate(): //Se ...

最新文章

  1. matlab 二分法求方程近似解
  2. 考察大新和南宁农业产业园 农业大健康·李喜贵:赋能乡村振兴
  3. 帝国cms调用栏目自定义字段(栏目简介)如何操作
  4. oracle易忘函数用法(5)
  5. Socket UDP无连接通信
  6. 基于ARM 构架(带MMU)的copy_from_user与copy_to_user详细分析
  7. centos忘记root用户的密码
  8. python精确小数点_如何确定小数点是否可以精确地表示为Python float?
  9. css分割线 文字居中的7种实现方式
  10. Android编程之另一种原因造成Cursor未关闭错误
  11. 快手面试官:Redis变慢了,如何快速排查?
  12. 第五团队谷歌浏览器软件与用户体验调查与分析
  13. linux驱动调试方法
  14. 多窗口键盘鼠标同步软件
  15. Nginx 跨域配置
  16. 软件无线电原理深入解析
  17. 六自由度机械臂研究(1)- 简介, 自由度与改装
  18. BuildPack:无需编写 Dockerfile,新一代的企业镜像打包工具
  19. 用Python爬取购物节当天热门商品销量数据,看看大家喜欢什么
  20. x86架构学习笔记实模式

热门文章

  1. 量子笔记:布尔逻辑/代数、逻辑门、通用门、可逆计算
  2. 我的世界服务器指令修复耐久,我的世界修改装备耐久度指令 | 手游网游页游攻略大全...
  3. ctfshow 萌新赛 劝退警告
  4. 学Git?这一篇就够了
  5. yii mysql gii_Yii 框架使用Gii生成代码操作示例
  6. 这篇文章有毒《持续更新中。。。》
  7. 基因序列 深度学习Deep Learning for Genomics: A Concise Overview
  8. 计算机网络自顶向下方法(二)——应用层
  9. 5G来临,我们该如何打造自己的家庭数据中心 - 基础篇
  10. 计算机自动执行的条件是,电脑中winsat.exe进程总会自动运行的解决方法