Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 362
refaelos Avatar asked Aug 02 '12 12:08

refaelos


People also ask

Can a service be bind with multiple components?

You can connect multiple clients to a service simultaneously. However, the system caches the IBinder service communication channel. In other words, the system calls the service's onBind() method to generate the IBinder only when the first client binds.

What is bindService in Android?

The client will receive the IBinder object that the service returns from its onBind(Intent) method, allowing the client to then make calls back to the service. The service will remain running as long as the connection is established (whether or not the client retains a reference on the Service's IBinder ).

How do you create a bound service?

There are three ways of creating bound services: First is by extending the binder class. Second is by using a messenger. Third, is by using AIDL or Android Interface Definition Language.

Which of the following method is called when all components bound to the service have been unbound?

A service is termed as bounded when an application component binds itself with a service by calling bindService() method. To stop the execution of this service, all the components must unbind themselves from the service by using unbindService() method.


1 Answers

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

like image 121
Arian Shahpasand Avatar answered Oct 12 '22 22:10

Arian Shahpasand