Skip to content

πŸ—„οΈ πšƒπš‘πš’πšœ πš›πšŽπš™πš˜πšœπš’πšπš˜πš›πš’ πšπšžπš’πšπšŽπšœ πšžπšπš’πš•πš’πš£πš’πš—πš π™°πš—πšπš›πš˜πš’πš π™Έπš—πšπšŽπš›πšπšŠπšŒπšŽ π™³πšŽπšπš’πš—πš’πšπš’πš˜πš— π™»πšŠπš—πšπšžπšŠπšπšŽ (𝙰𝙸𝙳𝙻) πšŠπš—πš πš’πš—πšŒπš•πšžπšπšŽπšœ πšŒπš˜πš–πš™πš›πšŽπš‘πšŽπš—πšœπš’πšŸπšŽ πšŒπš˜πš—πšπšŽπš—πš πšŒπš˜πšŸπšŽπš›πš’πš—πš πšŒπš˜πš—πšŒπšŽπš™πšπšœ πšŠπš—πš πšπš˜πš™πš’πšŒπšœ πš›πšŽπš•πšŠπšπšŽπš 𝚝𝚘 𝙰𝙸𝙳𝙻 πš’πš— π™°πš—πšπš›πš˜πš’πš πšπšŽπšŸπšŽπš•πš˜πš™πš–πšŽπš—πš.

License

Notifications You must be signed in to change notification settings

devrath/AIDL-Alchemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

𝙰𝙸𝙳𝙻-π™°πš•πšŒπš‘πšŽπš–πš’

Untitled Diagram drawio

πŸ—„οΈ πšƒπš‘πš’πšœ πš›πšŽπš™πš˜πšœπš’πšπš˜πš›πš’ πšπšžπš’πšπšŽπšœ πšžπšπš’πš•πš’πš£πš’πš—πš π™°πš—πšπš›πš˜πš’πš π™Έπš—πšπšŽπš›πšπšŠπšŒπšŽ π™³πšŽπšπš’πš—πš’πšπš’πš˜πš— π™»πšŠπš—πšπšžπšŠπšπšŽ (𝙰𝙸𝙳𝙻) πšŠπš—πš πš’πš—πšŒπš•πšžπšπšŽπšœ πšŒπš˜πš–πš™πš›πšŽπš‘πšŽπš—πšœπš’πšŸπšŽ πšŒπš˜πš—πšπšŽπš—πš πšŒπš˜πšŸπšŽπš›πš’πš—πš πšŒπš˜πš—πšŒπšŽπš™πšπšœ πšŠπš—πš πšπš˜πš™πš’πšŒπšœ πš›πšŽπš•πšŠπšπšŽπš 𝚝𝚘 𝙰𝙸𝙳𝙻 πš’πš— π™°πš—πšπš›πš˜πš’πš πšπšŽπšŸπšŽπš•πš˜πš™πš–πšŽπš—πš.

π™²πš˜πš—πšπšŽπš—πšπšœ
Demo
About AIDL
How communication occurs in the sample
How to run the sample application

Output

Demo.of.Client.mp4

About AIDL

  • AIDL is called Android Interface Definition Language.
  • It acts as an interface between the server and the client.
  • Both server and client agree to communicate using this interface.

Why AIDL is necessary

  • In Android normally processes do not communicate with each other.
  • If we want the processes to communicate with each other, We need to convert the data to primitives that the operating system can understand and then communicate, It is complex --> The AIDL makes this process simple to achieve.

When to use AIDL

  • Any method defined in your service to be accessed simultaneously by more than one applications.
  • If you want to share the data from your application so that other applications access it.

The data types supported by AIDL

  • All the primitive types like int, char, boolean, long, and so on...
  • String
  • CharSequence
  • List<Supported data type>
  • Map<Supported data type>
  • Generic maps, such as Map<String,Integer> are not supported.

How communication occurs in the sample

1 Server application

  • In the server application, We shall create an aidl file interface with methods exposed where on building the interface the code is generated behind the scenes by Android that takes care of marshaling the data that is used for communication.
  • Server defines a service class that extends an android service class and we Override the onBind method.
  • In the usual case of normally running the background service, We would return the IBinder as null but in our case here we will write an IBinder implementation.
  • The IBinder implementation will have all the abstract methods overridden and defined where we define the server implementations.

2 Client application

  • In the client also define the same aidl file as a server(You can even copy-paste it).
  • Now important to note is the package hierarchy must be the same here as the server else it won't work.
  • Build the project so that the Android generates code behind the scenes.
  • Define a service connection implementation
    • Here there are two methods onServiceConnected and onServiceDisconnected methods overridden.
    • At onServiceConnected method we get the reference to interface reference which requires IBinder as input to it and the reference is kept globally.
    • Using this reference we can access and communicate with the server.

3 Where we define the aidl files

Server Client
Screenshot 2024-02-15 at 11 32 52β€―PM Screenshot 2024-02-15 at 11 33 35β€―PM

4 How client initiates communication with server

  • We prepare an intent with inputs
    • It has an Intent filter name
    • The package name of the server
    • The component name that contains the service name in the server.
  • We call the bindService that has intent,service connection, and a flag to initiate the connection.
  • The earlier kept global reference is used to call the interface methods which in turn communicates with the server and gets the result from the server.

How to run sample application πŸ‘£

  • There are two applications in the repository. One is for server and another for client
  • Server consists of a service and does not contain any activity, client contains an activity that contains a button to initiate data retrieval from the server application.
  • Install the server App and install the client app also.
  • Now click the specific buttons on the client to retrieve specific data from the server.

πš‚πšžπš™πš™πš˜πš›πš β˜•

π™Έπš 𝚒𝚘𝚞 πšπšŽπšŽπš• πš•πš’πš”πšŽ πšœπšžπš™πš™πš˜πš›πš πš–πšŽ 𝚊 𝚌𝚘𝚏𝚏𝚎𝚎 πšπš˜πš› πš–πš’ πšŽπšπšπš˜πš›πšπšœ, 𝙸 πš πš˜πšžπš•πš πšπš›πšŽπšŠπšπš•πš’ πšŠπš™πš™πš›πšŽπšŒπš’πšŠπšπšŽ πš’πš.
π™±πšžπš’ π™ΌπšŽ 𝙰 π™²πš˜πšπšπšŽπšŽ

π™²πš˜πš—πšπš›πš’πš‹πšžπšπšŽ πŸ™‹β€β™‚οΈ

𝚁𝚎𝚊𝚍 πšŒπš˜πš—πšπš›πš’πš‹πšžπšπš’πš˜πš— πšπšžπš’πšπšŽπš•πš’πš—πšŽπšœ πšπš˜πš› πš–πš˜πš›πšŽ πš’πš—πšπš˜πš›πš–πšŠπšπš’πš˜πš— πš›πšŽπšπšŠπš›πšπš’πš—πš πšŒπš˜πš—πšπš›πš’πš‹πšžπšπš’πš˜πš—.

π™΅πšŽπšŽπšπš‹πšŠπšŒπš” ✍️

π™΅πšŽπšŠπšπšžπš›πšŽ πš›πšŽπššπšžπšŽπšœπšπšœ πšŠπš›πšŽ πšŠπš•πš πšŠπš’πšœ πš πšŽπš•πšŒπš˜πš–πšŽ, π™΅πš’πš•πšŽ πšŠπš— πš’πšœπšœπšžπšŽ πš‘πšŽπš›πšŽ.

π™΅πš’πš—πš πšπš‘πš’πšœ πš™πš›πš˜πš“πšŽπšŒπš πšžπšœπšŽπšπšžπš• ? ❀️

πš‚πšžπš™πš™πš˜πš›πš πš’πš πš‹πš’ πšŒπš•πš’πšŒπš”πš’πš—πš πšπš‘πšŽ ⭐ πš‹πšžπšπšπš˜πš— πš˜πš— πšπš‘πšŽ πšžπš™πš™πšŽπš› πš›πš’πšπš‘πš 𝚘𝚏 πšπš‘πš’πšœ πš™πšŠπšπšŽ. ✌️

π™»πš’πšŒπšŽπš—πšœπšŽ Licence πŸ’³

πšƒπš‘πš’πšœ πš™πš›πš˜πš“πšŽπšŒπš πš’πšœ πš•πš’πšŒπšŽπš—πšœπšŽπš πšžπš—πšπšŽπš› πšπš‘πšŽ π™°πš™πšŠπšŒπš‘πšŽ π™»πš’πšŒπšŽπš—πšœπšŽ 𝟸.𝟢 - 𝚜𝚎𝚎 πšπš‘πšŽ π™»π™Έπ™²π™΄π™½πš‚π™΄ πšπš’πš•πšŽ πšπš˜πš› πšπšŽπšπšŠπš’πš•πšœ.

About

πŸ—„οΈ πšƒπš‘πš’πšœ πš›πšŽπš™πš˜πšœπš’πšπš˜πš›πš’ πšπšžπš’πšπšŽπšœ πšžπšπš’πš•πš’πš£πš’πš—πš π™°πš—πšπš›πš˜πš’πš π™Έπš—πšπšŽπš›πšπšŠπšŒπšŽ π™³πšŽπšπš’πš—πš’πšπš’πš˜πš— π™»πšŠπš—πšπšžπšŠπšπšŽ (𝙰𝙸𝙳𝙻) πšŠπš—πš πš’πš—πšŒπš•πšžπšπšŽπšœ πšŒπš˜πš–πš™πš›πšŽπš‘πšŽπš—πšœπš’πšŸπšŽ πšŒπš˜πš—πšπšŽπš—πš πšŒπš˜πšŸπšŽπš›πš’πš—πš πšŒπš˜πš—πšŒπšŽπš™πšπšœ πšŠπš—πš πšπš˜πš™πš’πšŒπšœ πš›πšŽπš•πšŠπšπšŽπš 𝚝𝚘 𝙰𝙸𝙳𝙻 πš’πš— π™°πš—πšπš›πš˜πš’πš πšπšŽπšŸπšŽπš•πš˜πš™πš–πšŽπš—πš.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published