Is it ok to use bindService
more than once with the same context to the same service ?
Can I use bindService
multiple times with the same context to the same service and unBindService
only once ?
Thanks
Is it ok to use bindService
more than once with the same context to the same service ?
Can I use bindService
multiple times with the same context to the same service and unBindService
only once ?
Thanks
It is possible to bind multiply times to the same service with the same context, but it is looks to me as bad practice. Also, you cannot unbind from service only once. You must unbind all your ServiceConnection
's .
UPDATE: As for why it looks to me as a bad practice, it is because I can't imagine why one's will need that. Also I think connection wrapper which will bind and unbind only once and serve as facade interface to service could be better, because it'll introduce less overhead and less error prone (in my opinion though)
It doesn't matter how many time you call bindService if you use same context and the service is connected at the moment, android just ignore your call So you can just only bind to a service once with same context and unbind only once
When you call bind service the android framework check if the context is bind or not if the context is bind the android just ignore the call
© 2022 - 2024 — McMap. All rights reserved.