Android Service Testing

How to check my object IBinderthat Servicereturns on onBind?

+5
source share
1 answer

This is in accordance with the remote interface that you use between your context and the service (in the remote call script). For example, you can do the following:

IBinder service = this.bindService(new Intent(TestService.class.getName()));
assertNotNull(service);
assertTrue(service instanceof ITestServiceCall); //see if the service returns the correct interface
ITestServiceCall iTestServiceCall = ITestServiceCall.Stub.asInterface(service);
assertNotNull(iTestServiceCall);
iTestServiceCall.doSomething();

ITestServiceCall is the interface that you define in the AIDL file ( ITestServiceCall.aidl ).

But before this can work, you must ensure that your service correctly returns the Stub of your interface to onBind () .

Hope this helps.

+2

All Articles