Use of Aidl in Android

Source: Internet
Author: User

Aidl (Android Interface Definition language)
---------------------------------
Aidl is used to define the interfaces that need to be used when communicating across processes, that is, when multiple applications need to use the relevant interfaces, they should be defined using AIDL.
"Steps to define an interface using Aidl"
1. Create a Java interface file using a generic interface creation method
2. Delete the permissions for the created interface, i.e. public interface Imusicplayer modified to interface Imusicplayer
3. Open Windows Explorer, locate the interface file, and modify the extension aidl


Data types for Aidl
---------------------------------
Aidl is only recognized by default:
1. Basic data types, such as int, long, float, Boolean, etc...
2. String,charseqence
3. List
Custom data types:
1. Custom classes, such as music, and implement the Parcelable interface
2. Add the Aidl file of the custom class, for example Music.aidl, in which only the package statement, and Parcelable class name, such as Parcelable Music, can be
3. In the Aidl interface file, explicitly add an import statement, import a custom data type, such as import cn.tedu.ipc.Music, regardless of whether the current Aidl interface file and the Aidl file of the custom class are in the same package, you must explicitly guide the package
4. When cross-process access, the visitor (client) needs the service
The Aild interface file, the Java file of the entity class, the Aidl file of the entity class are all copied to the client, and the package name is guaranteed to be consistent with the server side.


Parcelable interface
---------------------------------
Implementation steps:
1. Custom classes, such as music, implement the Parcelable interface
2. Rewrite the Describecontents () method and return 0 directly
3. Rewrite the Writetoparcel () method, call the write??? of the parameter of the 1th parcel type Series method that writes the members of the current class (Music) class
4. Custom Readfromparcel (Parcel src) method, call Wite according to 3rd step??? Sequence of the series, calling the read??? of the parcel parameter in turn Series methods and assigns values to the individual members of the current class (Music)
5. Customize the construction method of the current class (Music) with the parcel parameter and call Readfromparcel () in the constructor method
6. Declare public static final parcelable.creator<music> Creator constants and assign them directly using the syntax of the anonymous inner class, in the anonymous inner class, public music[] NewArray ( int size) method to return directly to new Music[size], in public Music createfromparcel (Parcel src), return directly to create an object by constructing the method.

Use of Aidl in Android

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.