当前位置:网站首页>Two startup methods and differences of Service
Two startup methods and differences of Service
2022-08-11 07:51:00 【Is A small A】
Service startup method: startService() and bindService()
startService()
public abstract void startService(Intent service)
Parameters
Service name of the service program to be started
Methods
This method will call the onCreate() and onStartCommand() methods in the Service to start a background Service, and directly call the onDestroy() method when the Service is destroyed
bindService()
public abstract boolean bindService(Intent service,ServiceConnection conn,int flags)
Parameters
service is the name that defines the service program to bind
conn is the interface program responsible for receiving information when the service program starts and stops
flags are options for setting binding, which can be 0, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_NOT_FOREGROUND, BIND_ABOVE_CLIENT, BIND_ALLOW_OOM_MANAGEMENT or BIND_WAIVE_PRIORITY
Methods
This method starts the Service through the bindService() method, and its life cycle is controlled by its bound object.A Service can be bound to multiple objects at the same time. When no object is bound to the Service, the Service will be destroyed by the system
The difference between the two startup methods
1. startService just starts the Service, and the components that start it (such as Activity) are not associated with the Service. Only when the Service calls stopSelf or other components call stopService, the service will be terminated
2. The bindService method starts the Service, and the caller is bound to the service. Once the caller quits, the service will be terminated.
3. The bindService method starts the service. Other components can obtain the proxy object of the Service and interact with the Service through the callback, and the two parties are also bound. When the initiator is destroyed, the Service will also automatically perform the unBind operation.The Service will only be destroyed when all bindings have been unBinded
边栏推荐
- linux 安装mysql服务报错
- 网络电话软件或迎整顿 “免费”通话须迈安全关
- Activity的四种启动模式
- 1002 Write the number (20 points)
- Tensorflow中使用tf.argmax返回张量沿指定维度最大值的索引
- go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
- 语音信号处理:预处理【预加重、分帧、加窗】
- How do you optimize the performance of your Unity project?
- 那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
- JRS303-Data Verification
猜你喜欢
Serverless + domain name can also build a personal blog? Really, and soon
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
公牛10-11德里克·罗斯最强赛季记录
项目2-年收入判断
1.1-回归
1056 组合数的和 (15 分)
go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
Taobao product details API interface
测试用例很难?有手就行
查找最新人员工资和上上次人员工资的变动情况
随机推荐
【LeetCode】链表题解汇总
cdc连sqlserver异常对象可能有无法序列化的字段 有没有大佬看得懂的 帮忙解答一下
tf.reduce_mean()与tf.reduce_sum()
6月各手机银行活跃用户较快增长,创半年新高
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
为什么C#中对MySQL不支持中文查询
Unity3D learning route?
Strongly recommend an easy-to-use API interface
2022-08-09 Group 4 Self-cultivation class study notes (every day)
线程交替输出(你能想出几种方法)
4.1-支持向量机
How do you optimize the performance of your Unity project?
Unity底层是如何处理C#的
Unity程序员如何提升自己的能力
接入网、承载网、核心网是什么,交换机路由器是什么、这个和网络的协议有什么关系呢?
1.2-误差来源
接口测试的基础流程和用例设计方法你知道吗?
MySQL使用GROUP BY 分组查询时,SELECT 查询字段包含非分组字段
Service的两种状态形式
Unity开发者必备的C#脚本技巧