当前位置:网站首页>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
边栏推荐
- 深度监督(中继监督)
- 1106 2019数列 (15 分)
- 【软件测试】(北京)字节跳动科技有限公司二面笔试题
- redis操作
- 【Pytorch】nn.ReLU(inplace=True)
- Item 2 - Annual Income Judgment
- 软件测试主要做什么工作,难不难?
- 流式结构化数据计算语言的进化与新选择
- Internet phone software or consolidation of attack must be "free" calls security clearance
- How do you optimize the performance of your Unity project?
猜你喜欢
随机推荐
【软件测试】(北京)字节跳动科技有限公司终面HR面试题
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
Redis source code: how to view the Redis source code, the order of viewing the Redis source code, the sequence of the source code from the external data structure of Redis to the internal data structu
Tensorflow中使用tf.argmax返回张量沿指定维度最大值的索引
How Unity programmers can improve their abilities
JRS303-Data Verification
【Pytorch】nn.PixelShuffle
关于Excel实现分组求和最全文档
1076 Wifi密码 (15 分)
【LeetCode每日一题】——682.棒球比赛
Discourse 的关闭主题(Close Topic )和重新开放主题
3.2-分类-Logistic回归
【latex异常和错误】Missing $ inserted.<inserted text>You can‘t use \spacefactor in math mode.输出文本要注意特殊字符的转义
SQL滑动窗口
1002 Write the number (20 points)
Unity3D learning route?
关于Android Service服务的面试题
TF通过feature与label生成(特征,标签)集合,tf.data.Dataset.from_tensor_slices
There may be fields that cannot be serialized in the abnormal object of cdc and sqlserver. Is there anyone who can understand it? Help me to answer
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪









