From this series of articles, we know Proxy和Stub模式. In fact, 跨进程通信the so-called AIDL is to help us to achieve Proxy和Stub模式, to help us better package 编码and 译码function. Or the bottom transactand onTransactcalling methods.
Small example
Make a classic Echo program. Program to send word to the service, service to print out.
STEP 1: AIDL interface file (provided Service of APP)
Your service provider which interfaces to allow others to use, you have to make it clear that it does not need to be given at this time to achieve.
New com.example.aidlechoservice.aidlPackage
Create a regular file , namedIEchoService.aidl
1 2 3 4 5
package com.example.aidlechoservice.aidl;
interface{ String echo(String inStr); }
If you are using Eclipse, then we'll see after this definition creates gen/com.example.aidlechoservice.aidl/IEchoService.javafile
The second step: implement server-side Stub (providing Service of APP)
Super simple, just a word.
1 2 3 4 5 6 7
IEchoService.Stub mBinder = new IEchoService.Stub() { public String echo(String inStr)throws RemoteException { return"echo " + inStr + " at " + sdf.format(new Date()); } };