나는 나의 활동에 서비스 바인딩 : 지금까지 작동unregisterReceiver()가 onServiceDisconnected를 호출하지 않는 이유는 무엇입니까?
override fun onStart() {
Timber.d("onStart")
super.onStart()
val intent = Intent(this, MyService::class.java)
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
}
합니다. 그런 다음 bindService()
전화 onServiceConnected()
:에서
/** Defines callbacks for service binding, passed to bindService() */
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName,
service: IBinder) {
// We've bound to MyService, cast the IBinder and get MyService instance
val binder = service as MyService.MyBinder
myService = binder.service
isBound = true
registerReceiver(myBroadcastReceiver, filter)
}
override fun onServiceDisconnected(arg0: ComponentName) {
myService!!.removeRecevier([email protected])
isBound = false
unregisterReceiver(myBroadcastReceiver)
}
}
내 onStop()
또한 unbindService(serviceConnection)
가 있지만 여기 onServiceDisconnected()가 트리거되지 않습니다? 내가 뭘 잘못 했니?
그러므로 내가 얻을 :
Activity MainActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity MainActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
'myBroadcastReceiver'에 무엇이 필요합니까? 왜 당신은 당신의 서비스에 바인딩 한 후에 그것을 등록하기를 원합니 까? – pskink
그 서비스는 수신기와 아무런 관련이 없습니다. 둘 다 필요합니다. 오류 메시지로 인해 썼습니다. –
그래서'onStart'에 등록하고'onStop' (또는'onCreate' /'onDestroy')에 등록 해제하십시오 – pskink