Android--Bind service across apps (Aidl)

Source: Internet
Author: User
Tags event listener

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.