The previous chapter documented the cross-application launch service, before learning the difference and usage of startservice in Bindservice.
Using the Bindservice method, the activity requires the service to return a binder object, so if two applications are implemented, this involves a aidl concept.
Aidl (Android Interface Definition Language) is an IDL language used to generate interprocess communication between two processes on Android devices (interprocess communication, IPC) The code. You can use Aidl to generate serializable parameters if you want to invoke the operation of another process (such as a service) object in one process (for example, activity).
Let's look at how to use it,
First we need to create a aidl interface in the Service1 project.
I'm using Eclipse, create method, package name right –new–file–. aidl suffix name * *,
the Aidl file has its own input interface code.
After the file is created, the clear project will produce the appropriate Java files in the Gen directory.
Step Two
Enter the service modification Onbinder method in the Service1 project , the code is as follows
@Override publiconBind(Intent intent) { // TODO Auto-generated method stub returnnew IMyService.Stub() { @Override publicvoidbasicTypethrows RemoteException { // TODO Auto-generated method stub } }; }
At this point, a simple aidl is created successfully.
We go back to the SERVICE2 project and add the button event listener,
case R.id.button3: bindService(serviceIntent, this, Context.BIND_AUTO_CREATE); break; case R.id.button4: unbindService(this); break;
Successful completion of the service in the SERVICE2 Project binding Service1 Project
Android--Bind service across apps (Aidl)