Example of AIDL use
Asked Answered
C

5

60

to understand the AIDL in android, i want one real life example, means the at what scenario of development we need to use AIDL.

by reading the Android Docs ... It puts me in confusion and so many question, so it is hard to read whole doc for me, can anyone help me

  1. is it for communicating with outside the phone.

  2. or to communicating with different apps, (why we need to communicate with other apps)

  3. what kind of service they are talking in docs

Calvary answered 21/12, 2011 at 14:20 Comment(0)
T
48

AIDL is used for Binder. Binder is a mechanism to do RPC calls on/from an Android Service.

When to use AIDL? When you need a Service. When do you need a Service? If you want to share data and control something in another application, you need a service using AIDL as an interface. (A Content Provider is used when sharing data only).

Services can be used within your application as the model roll in the MVC-pattern.

Todd answered 21/12, 2011 at 14:30 Comment(3)
ok now i got it, thanks man, suppose for example if i want to control android inbuilt phone-dialer or may be in a case where i want to keep track on all the other application on the phone then I need to use AIDL...correct me if i am wrong.Calvary
It depends. Some information (like contacts) are available through content providers. You can see a content provider as a persistent data storage that is shared between applications for specific data. AIDL / services / binding is used for communicating. I mean, not only sharing data, but interacting with other components as well. By using AIDL it is be possible to telephony controls.Todd
Its also use to take a call back from Service to any Activity .Sagamore
B
31

AIDL is Android Interface Definition Language. This basically allows you to do IPC calls.

Use: There are situations where one process would need to talk to other to obtain certain information.

Example: Process A needs info of Call status to determine whether it needs to change Call Type (for example Audio to Video Call or Vice-versa). You may get call status from certain listeners but to change Call type from Audio to Video, Process A needs a hook to change. This "Hook" or way of changing calls is typically part of Telephony Classes which are part of Telephony Process. So in order to obtain such an information from Telephony process, One may write a telephony service (which runs as a part of android telephony process), which will allow you to query or change call type. Since Process A(Client) here is using this remote Service which communicates with Telephony process to alter call type, it needs to have an interface to talk to service. Since Telephony service is the provider, and Process A (client) is the user, they both need to agree on an interface (protocol) they can understand and adhere to. Such an interface is AIDL, which allows you to talk (via a remote service) to Telephony process and get some work done.

Simply put in laymen terms, AIDL is an "agreement" Client gets, which tells it about how to talk to service. Service itself will have a copy of that agreement(since it published for it's clients). Service will then implement details on how it handles once a request arrives or say when someone is talking to it

So process A requests to change call via Service, Service gets the request, it talks to telephony process(since it's part of it) and changes call to video.

An important point to note is, AIDL is only necessary for multithreading environment. You could do away with Binders if you don't need to deal with multithreaded arch.

Bunghole answered 20/8, 2014 at 22:32 Comment(1)
Nice explanation.Adalie
R
4

Another real world example is Google Play License is using AIDL.

Roshelle answered 25/1, 2015 at 9:43 Comment(0)
L
1

I have the same thinking about an example of AIDL, it's very difficult to find an idea to make an example app which uses AIDL. Then I have an idea about it create a LocalLogServerApp. Maybe it can not become a production app but it still shows some value in using AIDL

The main function of this app is

  • Receive the local log from other local apps (another app need to implement AIDL to send log)
  • Save the log to datastore
  • Display the logs
  • Maybe do something with the local log (eg: search, delete)
  • Maybe notify developer when error log happened

The benefit of this app

  • The local log can use when you have some very strange issues which sometimes happened in a few moments and in some specific device. In this case, common Log won't help, debug won't help, Firebase Log may help but Firebase receive log from multiple device.
  • Reusable, many apps can use it with less code

Hope you find this idea helpful to find another better AIDL example https://github.com/PhanVanLinh/AndroidLocalLogServer https://github.com/PhanVanLinh/AndroidLocalLogClientTest

Laetitia answered 28/1, 2021 at 9:12 Comment(0)
S
0

1 - is it for communicating with outside the phone. Its communicating with outside the app.

2 - or to communicating with different apps, (why we need to communicate with other apps) As @GodOnScooter mentioned, when your app communicates with telephony service which is actually an other part.

3 - what kind of service they are talking in docs?

This is a service which runs in different process of a system, To bind to this service you need IPC(inter process communication), AIDL is used to implement this.

Saleratus answered 25/4, 2017 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.