Android Interface Definition Language-aidl (2)

Source: Internet
Author: User

1. Create a. aidl File

Aidl uses simple syntax to declare interfaces with multiple methods. These methods can contain parameters and return values. Parameters and return values can be of any type, or even interfaces generated by other aidl.

The. aidl file must be built using the Java programming language. Each. aidl file must define a single interface and require only interface declarations and method signatures.

By default, aidl supports the following data types:

1. All original data types in Java (such as int, long, Char, and Boolean );

2. String

3. charsequence

4. List

All the elements in the list must be the data types supported in this list, the interfaces generated by other aidl, or the types you declare. You can select to use a type class (such as list <string>) for list ). Although the method is generated using the list interface, the acceptance class is always the arraylist class.

5. Map

All elements in the map must be the data types supported in this list, the interfaces generated by other aidl, or the types you declare. Parameter map (such as Map <string, integer>) is not supported ). Although the map interface is used to generate methods, the actually accepted class is always hasmap.

Other types not listed in the preceding list must contain an Import Statement, even defined in the same package as the interface.

When defining a service interface, note the following:

1. The method can contain 0 or multiple parameters and return a value or void;

2. All non-basic parameters must be marked in a direction to indicate the data direction, either in or out (for details, see the following example ).

The default value is in.

Warning you should limit the data direction to the desired direction, because grouping parameters are a waste of resources.

3. All code comments contained in the. aidl file will be included in the generated ibinder interface (except the comments before the import and package statements ).

4. Only methods are supported. static fields in aidl cannot be exposed.

The following is an example of a. aidl file:

// Iremoteservice. aidl

Package com. example. Android;

 

// Declare any non-default types here with import statements

 

/** Example service interface */

Interface iremoteservice {

/** Request the process ID of this service, to do edevil things with it .*/

Int getpid ();

 

/** Demonstrates some basic types that you can use as parameters

* And return values in aidl.

*/

Void basictypes (INT anint, long along, Boolean sort lean, float afloat,

Double Adouble, string astring );

}

Simply save the. aidl file to the src/directory of the Project. when compiling the application, the SDK tool will generate the ibinder interface file in the GEN/directory of the project. The generated file name matches the. aidl file name. It only uses the. Java extension (for example, iremoteservice. aidl, And the generated result is iremoteservice. Java ).

If eclipse is used, incremental compilation almost immediately generates the biner class. If you do not use eclipse, the ant tool will generate the biner class when you compile the application next time-you should complete the compilation. use ant debug (or ant release) to compile the project immediately after the aidl file, so that your code can be linked to the generated class.

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.