8000 GitHub - shvmsaini/AIDL-Usage: Serves as an Example on how to use AIDL for IPC across different apps. · GitHub
[go: up one dir, main page]

Skip to content

About

Serves as an Example on how to use AIDL for IPC across different apps.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Android AIDL Demonstration Project

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.

Features

  • Remote Service: A background service in the Server app providing calculation and messaging services.
  • Bi-directional Communication: Uses RemoteCallbackList to 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.

Project Structure

  • :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.

Screenshots

1. Server Application

The Server UI displays real-time statistics, including the number of active listeners and the last received message.

Server Screenshot

2. Client Application

The Client UI allows users to bind to the service, invoke methods, and see real-time callback events pushed from the server.

Client Screenshot


Getting Started

Prerequisites

  • Android Studio Ladybug or newer.
  • Two Android devices or emulators (to run both apps simultaneously).

Installation

  1. Clone this repository.
  2. Open the project in Android Studio.
  3. Build and Run the Server App (:app) first.
  4. Build and Run the Client App (:client).

How to use

  1. Launch both applications.
  2. In the Client App, click the "Bind Service" button.
  3. Once connected, enter a name in the text field and click "Call getMessage()".
  4. Observe the results in the Client UI and the updated stats in the Server UI.

AIDL Interface Contract

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);
}

Technical Notes

  • Binder Threading: AIDL calls on the server side are executed on a binder thread pool. The UI updates are handled using StateFlow and runOnUiThread.
  • 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.

About

Serves as an Example on how to use AIDL for IPC across different apps.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0