Simonlbc
Simonlbc

Reputation: 641

bindService() in client app fails when trying to do IPC with another app

I wanted to get some experience with android IPC using AIDL. I wanted to see if it was possible to communicate between two distinct android apps.

My problem is that invoking bindService in the second app, to communicate with the first app's FactorialService, service always fails. My first app activity MainActivity which tries to call bindService always log the fact that bindService returns false. Plus MainActivity (which implements ServiceConnection) of this second app (the client app) never gets its callback method onServiceConnected called.

So, in a first application which runs a service called FactorialService

FactorialRequest contains an input number (say n). fact returns n! along with other information.



But it seems bindService fails. Indeed everytime I pause the app and return to it, or start it. "Failed to bind our service!!!" is displayed.

Note that the two app share an Android Library module containing the definitions of the needed aidl files.

Do you see anything that would allow bindService() to work?

Upvotes: 0

Views: 859

Answers (1)

Ankur Aggarwal
Ankur Aggarwal

Reputation: 2220

Why are you using super.bindservice() ? Instead, can you try this getApplicationContext().bindservice()

Also, if this does not work either, try the following modification of your code:

   Intent i = new Intent("com.example.simonlbc.factorialservice.FactorialService");
   if(getApplicationContext().startService(i) != null){
       if (!getApplicationContext().bindService(i, serviceConnection, 0))
           Log.w(TAG, "Failed to bind our service!!!");
   }

where seriveConnection is an object of service connection (I prefer not to use this for ServiceConnection ). Also, your service should have the proper Action set, otherwise it won't start

Upvotes: 1

Related Questions