I was wondering when does Context.bindService()
return false
?
I've tried to make the onBind()
return null
, but it still returns true
when bindService
is called and the onServiceConnected
does not get executed. I also saw this on Google Groups with no response
https://groups.google.com/forum/#!topic/android-developers/ZLl56Mz1jYg
I also can't find the implementation of bindService, since it is abstract in Context.java and searching for "public boolean bindService" does not yield any useful results either (closest was ApplicationContext which does not seem to be present in the current API levels).
It allows components (such as activities) to bind to the service, send requests, receive responses, and perform interprocess communication (IPC). A bound service typically lives only while it serves another application component and does not run in the background indefinitely.
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.
Services is the Android component which is used to perform long-running background tasks. There are other Android components which run in the background too, like Broadcast receiver and JobScheduler, but they are not used for long running tasks.
One very common case in which bindService returns false is if the service was not declared in the Manifest. In that case you should add code like seen below to your manifest file
<manifest ... >
...
<application ... >
<service android:name=".ExampleService" />
...
</application>
</manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With