This project demonstrates the implementation of AIDL (Android Interface Definition Language) for Inter-Process Communication (IPC) between two separate Android applications: a Server and a Client.
- Remote Service: A background service in the Server app providing calculation and messaging services.
- Bi-directional Communication: Uses
RemoteCallbackListto push updates from the Server back to the Client. - Modern Architecture: Implemented using Jetpack Compose for UI and MVVM for logic separation.
- Package Visibility: Configured for Android 11+ compatibility.
:app- The Server Application (io.github.shvmsaini.server). Hosts the AIDL service.:client- The Client Application (io.github.shvmsaini.client). Binds to and interacts with the server.
The Server UI displays real-time statistics, including the number of active listeners and the last received message.
The Client UI allows users to bind to the service, invoke methods, and see real-time callback events pushed from the server.
- Android Studio Ladybug or newer.
- Two Android devices or emulators (to run both apps simultaneously).
- Clone this repository.
- Open the project in Android Studio.
- Build and Run the Server App (
:app) first. - Build and Run the Client App (
:client).
- Launch both applications.
- In the Client App, click the "Bind Service" button.
- Once connected, enter a name in the text field and click "Call getMessage()".
- Observe the results in the Client UI and the updated stats in the Server UI.
package com.example.aidl;
import com.example.aidl.IMyAidlCallback;
interface IMyAidlInterface {
String getMessage(String name);
int addNumbers(int a, int b);
void registerCallback(IMyAidlCallback cb);
void unregisterCallback(IMyAidlCallback cb);
}- Binder Threading: AIDL calls on the server side are executed on a binder thread pool. The UI updates are handled using
StateFlowandrunOnUiThread. - RemoteCallbackList: Used to safely manage multiple client callbacks and handle process death automatically.
- Security: The service is exported but can be further secured with custom permissions if needed.