当前位置:网站首页>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
边栏推荐
猜你喜欢
1091 N-自守数 (15 分)
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
1051 复数乘法 (15 分)
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
1036 跟奥巴马一起编程 (15 分)
1002 Write the number (20 points)
我的创作纪念日丨感恩这365天来有你相伴,不忘初心,各自精彩
详述 MIMIC护理人员信息表(十五)
tf中矩阵乘法
Tensorflow中使用tf.argmax返回张量沿指定维度最大值的索引
随机推荐
SQL sliding window
prometheus学习4Grafana监控mysql&blackbox了解
easyrecovery15数据恢复软件收费吗?功能强大吗?
【软件测试】(北京)字节跳动科技有限公司终面HR面试题
线程交替输出(你能想出几种方法)
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
网络电话软件或迎整顿 “免费”通话须迈安全关
Dynamic Agent Learning
JRS303-Data Verification
How Unity handles C# under the hood
无服务器+域名也能搭建个人博客?真的,而且很快
Service的两种启动方式与区别
Tidb二进制集群搭建
【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
Activity的四种状态
详述 MIMIC护理人员信息表(十五)
1071 小赌怡情 (15 分)
matplotlib
Unity3D 学习路线?
Serverless + domain name can also build a personal blog? Really, and soon