Understanding android Messenger and AIDL of Concurrency API

Now we got one more day to learn something new about the Service, Ok let’s make today something awesome to learn more about the service of concurrency API. In my last article, we understand about the Concurrency API of Service and Intent Service and Bound Service. In this article, we will learn about service which uses the technique of Messenger and AIDL. Wow Sounds great :).

Bound Service (Messenger and AIDL)

In this article, I am focusing on the bound services which are running in the background in the different process in the single thread and multi-thread environment. If we talk about the Single thread for sending the message in a queue the first thing comes to mind is that Messenger.


Messenger will process the message in a different process by using IPC (Inter Process Communication) remote technique to communicate with client and server. Messenger will be coupled with the handler, hence all the task will be in queue process in a Single thread by Handler.

For bind the service what you need to do with pass the Messenger instance reference in onBind() method and pass the reference of handler while creating the Messenger instance. Hereabouts message will be carried in the format of the bundle with Messenger that it awesome. Let’s see for example to create one service which runs in the different process by using Messenger which is the coupled by Handler.

Now let’s create activity class to bind this service to send the message to this server and again send back this response from server to client by using Messenger process by the handler.

Here also required the Service Connection to build the connection between the client and the server. The handler will process the response of Messenger and update the user interface. But one more thing does not forget to add this service in AndroidManifest.xml.

Wow, Messenger is awesome to communicate with server and client. Let’s check how is AIDL works in different process.


AIDL means android interface definition language.It can process any task remotely by using IPC technique. Android has a strong mechanism to communicate between service and client through IPC technique. AIDL process the data between clients remotely and safely only thing is required that client should be bind to this services. AIDL support to process the generic data by using the Parcelable. Data processing through Parcelable is fast in IPC mechanism. Different process means I am talking about the communication between two different applications.

Let’s take a simple word to define AIDL IPC mechanism, suppose you have App1 consider as a remote server that running AIDL service. What does this service? it gets the list of users information of table and process data to the client or any business logic that get information from the client and do some task and give a response back to the client (It means App2). Here the user model should be Parcelable for fast communication.

I think it’s big complex example, Let’s give another simple example to explain. I want to multiply by given two numbers. I will pass two different numbers as input and will tell to AIDL service to give the result as a response back to me.  It is simple task here but it can take any long background task to the process, for example, downloading any audio or video files from the server.

For communication with two different apps or process, I need to create the AIDL file in the same package of both apps. Why AIDL is required on client side also it will create the copy of proxy for remote access.

Let’s create two different android studio project for App1 and App2.

You need to set the build and sync to access the aidl file.

Add the service in AndroidManifest.xml file.

Now in App2, I will try to access the service to get the result. You need to bind via explicit intent service with the client by ServiceConnection.

Here is the xml file.

Wow AIDL is the really awesome feature of service that running in the background in multi-thread environment and its IPC mechanism is very strong to communicate remotely.

Here are the best offer and recommendation for you to download this. I  used the reference from my old post which is posted here and here. Please do subscribe your email to get every newsletter from this blog and if you feel that this post helps you then do not forget to share and comment below.

Happy Coding 🙂

I am a very enthusiastic Android developer to build solid Android apps. I have a keen interest in developing for Android and have published apps to the Google Play Store. I always open to learning new technologies. For any help drop us a line anytime at contact@mobologicplus.com

Leave a Reply

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