Cross-application services in Android are based on Binder, a kernel-level IPC system (this is where the IBinder
class name comes from). When you bind to a remote service (that is, one outside of your application), it can return an object to you. However, since you don't know what the actual type is (methods, fields, etc), you can't cast it to a usable type.
This is where AIDL comes in - it is a language-agnostic way of specifying interfaces - collections of methods and their parameters (it also looks deceptively like Java - it's not). If both the client and the server use the same .aidl file, you can bind to the object via the generated Java interfaces - IRemoteService.Stub.asInterface(obj)
. On the service side you just have to implement that same interface in some language (some of the services in the framework are in C++) and the IPC mechanism will take care of the rest.
That said, you don't need to use AIDL unless you export your service and want external applications to be able to use it. If not, just implement IBinder in your application and cast the object received in onServiceConnected
directly, since you know its type.