A demonstration project showcasing Android's Inter-Process Communication (IPC) capabilities using AIDL (Android Interface Definition Language). This project consists of two separate Android applications: an IPC server that provides a calculator service and an IPC client that consumes this service.
Inter-Process Communication (IPC) in Android allows different applications or processes to communicate with each other securely. This demo implements a simple calculator service that can be accessed by external applications through Android's Binder mechanism.
- IPC Server (
com.duongpt.ipcserver) - Provides calculator functionality as a service - IPC Client (
com.duongpt.ipcclient) - Consumes the calculator service and demonstrates remote method calls
com.duongpt.ipcserver/
├── MainActivity.java # Main activity with basic UI
├── CalculatorService.java # Service implementing calculator functionality
└── ICalculator.aidl # AIDL interface definition
Key Components:
- MainActivity: Basic Android activity serving as the app entry point
- CalculatorService: Android Service that implements the
ICalculatorinterface and handles remote method calls - ICalculator.aidl: AIDL interface defining the contract for calculator operations
com.duongpt.ipcclient/
├── MainActivity.java # Main activity with calculator UI and service binding
└── ICalculator.aidl # Copy of server's AIDL interface for binding
Key Components:
- MainActivity: Contains UI elements and service connection logic to interact with the remote calculator service
- ICalculator.aidl: Identical copy of the server's AIDL interface required for client-side binding
- Cross-Application Communication: Demonstrates communication between two separate Android apps
- AIDL Interface: Uses Android Interface Definition Language for defining service contracts
- Service Binding: Implements proper service binding and connection management
- Remote Method Invocation: Shows how to call methods on remote services
- Connection State Handling: Includes proper handling of service connection and disconnection
- Security: Implements package queries for Android 11+ compatibility
- Target SDK: 36
- Minimum SDK: 24 (Android 7.0)
- Language: Java
- Build System: Gradle
- Architecture: Client-Server IPC using Android Binder
- Communication Protocol: AIDL (Android Interface Definition Language)
- Android Studio (latest version recommended)
- Android SDK API 24 or higher
- Android device or emulator running Android 7.0+
-
Clone the repository
git clone <repository-url> cd IPCAndroid
-
Open both projects in Android Studio
- Open
IPCServerproject - Open
IPCClientproject in a separate window
- Open
-
Build both applications
# Build IPC Server cd IPCServer ./gradlew build # Build IPC Client cd ../IPCClient ./gradlew build
-
Install both apps on your device/emulator
- Install IPC Server app first
- Install IPC Client app second
-
Start the IPC Server
- Launch the IPC Server app
- The app will register the calculator service
-
Use the IPC Client
- Launch the IPC Client app
- The app will automatically attempt to bind to the calculator service
- Click "Add 5 + 3" button to test the remote calculation
- The result should display: "Result: 8"
The ICalculator.aidl file defines the contract:
interface ICalculator {
int add(int x, int y);
}The server implements the AIDL interface:
final ICalculator.Stub mBinder = new ICalculator.Stub() {
@Override
public int add(int x, int y) throws RemoteException {
return x + y;
}
};The client binds to the service using an explicit intent:
Intent intent = new Intent("com.duongpt.ipcserver.RUN_SERVICE");
intent.setPackage("com.duongpt.ipcserver");
bindService(intent, serviceConnection, BIND_AUTO_CREATE);- Client app creates an intent targeting the server's service
- Android system establishes a Binder connection
- Client receives an IBinder object through ServiceConnection callback
- Client converts IBinder to ICalculator interface using
ICalculator.Stub.asInterface() - Client can now call remote methods as if they were local
IPCAndroid/
├── IPCServer/ # Server application
│ ├── app/
│ │ ├── src/main/
│ │ │ ├── java/com/duongpt/ipcserver/
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── CalculatorService.java
│ │ │ ├── aidl/com/duongpt/ipcserver/
│ │ │ │ └── ICalculator.aidl
│ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ └── settings.gradle
├── IPCClient/ # Client application
│ ├── app/
│ │ ├── src/main/
│ │ │ ├── java/com/duongpt/ipcclient/
│ │ │ │ └── MainActivity.java
│ │ │ ├── aidl/com/duongpt/ipcserver/
│ │ │ │ └── ICalculator.aidl
│ │ │ └── AndroidManifest.xml
│ │ └── build.gradle.kts
│ └── settings.gradle.kts
└── README.md
- Package Queries: The client app includes
<queries>element in AndroidManifest.xml for Android 11+ package visibility - Exported Service: The server service is marked as
exported="true"to allow external access - Intent Filtering: Server service uses intent filters for controlled access
- Package Targeting: Client uses explicit package targeting to prevent intent hijacking
You can extend this project by:
- Adding more mathematical operations (subtract, multiply, divide)
- Implementing data transfer objects using Parcelable
- Adding authentication/authorization mechanisms
- Creating more complex service interactions
- Implementing callbacks from server to client
duongpt - Initial work
This project is open source and available under the MIT License.
This project demonstrates fundamental Android IPC concepts and serves as a learning resource for Android developers interested in inter-process communication.