refaelos
refaelos

Reputation: 8055

Android - bindService more than once

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

Upvotes: 13

Views: 8453

Answers (3)

Modern Android
Modern Android

Reputation: 71

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

Upvotes: 1

Arian Shahpasand
Arian Shahpasand

Reputation: 300

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

Upvotes: 3

pepyakin
pepyakin

Reputation: 2235

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)

Upvotes: 8

Related Questions