关于onServiceDisconnected不会被调用的问题

当主动停止Android Service时,onServiceDisconnected方法通常不会被调用,除非服务所在的进程崩溃或被杀死。此时,ServiceConnection保持活跃,并在Service下次运行时重新调用onServiceConnected。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在获得一个ServiceConnection实例时需要覆写onServiceConnectedonServiceDisconnected两个方法,一直疑惑onServiceDisConnected方法为什么在主动unbindService后不会调用,查了官方文档后有初步的了解

Called when a connection to the Service has been lost. This typically happens when the process hosting the service has crashed or been killed. This does not remove the ServiceConnection itself – this binding to the service will remain active, and you will receive a call to onServiceConnected(ComponentName, IBinder) when the Service is next running. 原文 Android Developer

大概的意思是onServiceDisconnected只会在Service丢失时才会调用, 通常会在Service所在进程被迫终止时才会调用, 当Service重新运行时会再次调用onServiceConnected方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值