Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in what case does bindService return false?

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).

like image 785
Archimedes Trajano Avatar asked Jul 22 '13 04:07

Archimedes Trajano


People also ask

What does bindService do?

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.

What is the use of onBind() in android?

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.

Why we use bound service?

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.


1 Answers

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>
like image 185
PeterErnsthaft Avatar answered Oct 12 '22 13:10

PeterErnsthaft