Android Getting Started Tutorial Aidl simple Introduction

Source: Internet
Author: User

A recent project to be done with the Aidl (Android Interface Definition Language: Interface Description Language) technology, a simple glance at the Wheat Academy Android Development Video tutorial, I understand that it is similar to the concept of RMI in Java, so I try to test it myself. No more nonsense, just start.
1, since Aidl is able to operate between different processes, then we need to prepare two items first, we first to look at the different two project structure of what it looks like.
 Let's first define a project as "server-side project", one for "client project", where the purple wireframe is the first thing to notice, that is, no matter how different your two package names are, the Aidl file must be placed under the same package, with the same name.
2, we have now created the project, the next step is to develop the calling interface and implementation methods. In fact, the Aidl file serves as a interface class in which you can write a call interface that you want to publish to the client. (I will not write the specific code, you can see my uploaded items) when writing Aidl interface, it should be noted that the class must be the same as your Aidl file name, you must indicate the current package path, if it is a common type, such as: String, List, int, void, etc. There is no need to import the package path, when the external class is used, it is necessary to import the package path where the class is located; When writing a method, each parameter must specify in or out to indicate whether it is an input parameter or an output parameter.
3, since Aidl we finished, then of course is going to implement this interface, let it to help us do things, aidl because it is a remote call, so here your implementation class must be a class to inherit the service, and then in this implementation class to do the Aidl implementation method. Testservice is my implementation class, the specific code also see my uploaded items. However, in testservice it is important to note that the Onbind method must return the Aidl instance object that you implement for the remote caller to use
Public IBinder Onbind (Intent Intent) {
return binder;
}
4, the service side manifest.xml need to make the following configuration, or your client calls will not be able to get your aidl object, I did the test before, has been plagued by this problem.
<serviceandroid:name= "Testservice" android:process= ": Remote" >
<intent-filter> Configure your Aidl interface full path
<actionandroid:name= "Com.lifeblood.ITestService"/>
</intent-filter>
<rvice>
5, after the work of the server, we began to do the client's work. The client is actually very simple, copy the server's aidl, create a serviceconnection used to get the remote Onbind to pass over the Aidl interface object, Then you can start using the method in Aidl by binding bindservice at startup.

more Android Development tutorials at: Http://www.maiziedu.com/course/android/


Android Getting Started Tutorial Aidl simple Introduction

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.