Hello Guys !!! Hope You all are doing well. Today I am going to discuss AIDL and its uses in Android Application.
AIDL (Android Interface Definition Language) is similar to other
IDLs.
It allows us to define the programming interface that both the client
and service agree upon in order to communicate with each other using
interprocess communication (IPC).
On Android, one process cannot normally access the memory of another
process. So to talk, they need to decompose their objects into
primitives that the operating system can understand, and marshall the
objects across that boundary for you. The code to do that marshalling
is tedious to write, so Android handles it for us with AIDL.
# When to use AIDL
- Clients from different applications want to access your service for IPC.
- Your service want to handle multithreading for IPC(any method defined in service can be executed simultaneously by more than one application).
- If you want to share data and control something in another application.
- You want to create some new functionalities and distribute them as a library.
#
AIDL Implementation Steps
In order to allow for one application to call into another, we
typically have to:
- Define the AIDL interface
- Implement the Stub for the remote service
- Expose the remote service to the local client
#
The data types supported by AIDL
-
All primitive types (Supported by Java such as int, long, char, boolean, and so on)
-
String
-
CharSequence
-
List(must be one of the supported data types or parcelables)
-
Generic List such as List<String> supported
-
Map (must be one of the supported data types or parcelables )
-
Generic maps, such as Map<String,Integer> are not supported
#
Defining the AIDL
-
AIDL syntax is very similar to regular Java interface , Define AIDL interface in an .aidl
-
Then save it in the source code (in the src/ directory) of both the application hosting the service and any other application that binds to the service.
-
When you build each application that contains the .aidl file, the Android SDK tools generate an IBinder interface based on the .aidl file and save it in the project's gen/ directory.
#
Steps for creating a bounded service using AIDL
1. Create the
.aidl file
This file defines the programming interface with method signatures.
2. Implement the
interface
The Android SDK tools generate an interface in the Java programming
language, based on your .aidl file. This interface has
an inner abstract class named Stub that extends Binder and implements
methods from your AIDL interface. You must extend the Stub class and
implement the methods.
3. Expose the
interface to clients
Implement a Service and override onBind() to
return your implementation of the Stub class.
Note:
-
Any changes that you make to your AIDL interface after your first App release must remain backward compatible in order to avoid breaking other applications that use your service.
-
That is, because your .aidl file must be copied to other applications in order for them to access your service's interface, you must maintain support for the original interface.
In above example, I am using two application Client App and Server App. Client App will get number from user and send it to server.
Server App will receive number from client and perform addition and send result back to client App.
In my example code App is server App and app2 is client App.
Hope you people enjoy it. Flow Diagram for AIDL.
Happy Coding !!!
Thanks
Saurabh
I really appreciate the information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in #APACHE #CAMEL, kindly Contact MaxMunus
ReplyDeleteMaxMunus Offer World Class Virtual Instructor-led training on #APACHE #CAMEL. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 1,00,000 + training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
Avishek Priyadarshi
MaxMunus
E-mail: avishek@maxmunus.com
Skype id: avishek_2.
Ph:(0) 8553177744 / 080 - 41103383
www.MaxMunus.com
With the technology improves, many industries has to be update to beat their competitors. Mobile Application Development Company India is increasing massively due to the immense development and android mobile phone users. This is some extra points to be added from my point of view.
ReplyDeleteRegards:
Android Course in Chennai | Android Training Chennai
Very useful information that you have shared and it is very useful to me.Thanks for sharing the information with us.
ReplyDeletebest mobile app development company in chennai
This blog enabled me to achieve my learning objectives on this topic. Thanks for the efforts taken in sharing the thoughts with us.
ReplyDeleteSpoken English Classes in Anna Nagar
Spoken English Classes in Chennai Anna Nagar
Spoken English Classes in Porur
Spoken English Class in Chennai Porur
Spoken English Classes in T-Nagar
Spoken English Classes in Vadapalani
Spoken English Class in Thiruvanmiyur
Spoken English Classes in Adyar
Very useful post. Thank you for sharing with us.
ReplyDeleteramanichandran novels free download
muthulakshmi raghavan novels free download
sashi murali novels free download
tamil novels pdf
srikala tamil novels
mallika manivannan tamil novels
Thanks for sharing this post
ReplyDeletea href="https://hanumanchalisalyricspdf.in/">Hanuman Chalisa Lyrics Pdf
Hanuman Chalisa Tamil Pdf
Hanuman Chalisa English Pdf
Hanuman Chalisa Telugu pdf