Android AIDL Remote Service Tutorial

What is AIDL in android? AIDL is Android Interface definition language to establish the communication both application that running at different process. The communication is using IPC inter process communication which allow the process communicate together. In Android OS, different process cannot access to another process. Therefore, Android was solve this problem by using AIDL convert the object to primitive so that the Android OS will understand. It also name as remote service. In this tutorial, i will give you the example and show how the its work in android. It is just easy if you can understand the process.

Create a new project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “AIDL_SBServiceExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Project” and Click Next button
5. Lastly, press finish button.

Add a new Service

Create a new service in your package name by right click > Add > Service > Service. Enter the Service name as “AIDLService”, after that click OK button. Once service class created, you will see <service> is include in your AndroidManist.xml.

Create a new aidl file

To add a aidl interface by right click the package name > New > AIDL >AIDL File. The aidl default name is IMyAidlInterface you can change it or let it default. After that click finish button.

After that, it will automatic generate the aidl package for your aidl file.

Edit IMyAdilInterface.aidl interface

Open your IMyAidlInterface.aidl in your aidl package and insert the following code.

Edit AIDLService.java class

After that, go to your AIDLService.java add the following code.

Add a new Module in your project

Create a new module name “anotherapp” to start, bind and syn data to the module “app”(service). Different module is a different application, so they have different process. The module “anotherapp” is to connect the service from the “app” module. To create a new module, in the topbar click File > New > New Module.

It will pop out a task, select Phone and Tablet Module, Next and pick the Empty Activity finally finish.

Edit activity_main.xml layout

In the “anotherapp” module, go to the activity_main.xml in the layout folder edit the source code.

Add a new AIDL folder

In the “anotherapp” module add a new aidl folder.

Copy aidl package and paste it

Copy the aidl package in the “app” module and paste it in your aidl package in the “anotherapp” module. The package name and aidl file name should same as module “app”.

Edit MainActivity.java class

In the module “anotherapp“, go to the MainActivity.java and add the following code.

Run “app” module first

You need to start the module “app” first, after that that only start the module “anotherapp” to test the service in your device.

Yes… you just done this project. You can test out the application and understand how its work.

(Android AIDL Remote Service)

Source Code

(Visited 768 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

GET YOUR EBOOK FOR FREE

Unlock free ebook "Beginning Programming ALL-IN-ONE Desk Reference for DUMMIES" now!

We will send a copy to your email