When would you use AIDL?

Technology CommunityCategory: AndroidWhen would you use AIDL?
VietMX Staff asked 3 years ago

AIDL does nothing but lets the system to generate the boilerplate code that hides the binder IPC details, so that you can invoke the remote service API as a local method call. Using AIDL is necessary only if you allow clients from different applications to access your service for IPC and want to handle multithreading in your service. So,

  1. If you don’t need IPC (i.e., your client and server stay in the same process), you don’t need AIDL;
  2. If you want to write the boilerplate code yourself for IPC, you don’t need AIDL;
  3. If your service is not complicated enough (i.e., does not require concurrent multithreaded accesses), you can use system provided Messenger API for IPC. You don’t need your own AIDL, because the Messenger API hides the AIDL usage;
  4. To extend the case 3, if you can use any existing lib or existing API to access a service in another process, you don’t need your own AIDL. For example, you can access ActivityManagerService with existing system API, and all the AIDL stuff for IActivityManager is hidden by the system API.