当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
接口测试的基础流程和用例设计方法你知道吗?
Test cases are hard?Just have a hand
3.2-分类-Logistic回归
分布式锁-Redission - 缓存一致性解决
项目1-PM2.5预测
【软件测试】(北京)字节跳动科技有限公司二面笔试题
1003 我要通过 (20 分)
无服务器+域名也能搭建个人博客?真的,而且很快
恒源云-Pycharm远程训练避坑指南
Evolution and New Choice of Streaming Structured Data Computing Language
How do you optimize the performance of your Unity project?
你是如何做好Unity项目性能优化的
Edge provides label grouping functionality
break pad源码编译--参考大佬博客的总结
Depth (relay supervision)
关于Android Service服务的面试题
redis操作
Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
Unity程序员如何提升自己的能力
Discourse 的关闭主题(Close Topic )和重新开放主题