Create an aidl File

AIDL is a simple syntax that lets you declare an interface with one or more methods, that can take parameters and return values. These parameters and return values can be of any type, even other AIDL-generated interfaces. However, it is important to note that you must import all non-built-in types, even if they are defined in the same package as your interface. Here are the data types that AIDL can support:

• Primitive Java programming language types (int, boolean, etc) — No import statement is needed.

• One of the following classes (no import statements needed):

o String o List - All elements in the List must be one of the types in this list, including other AIDL-generated interfaces and parcelables. List may optionally be used as a "generic" class (e.g. List<String>). The actual concrete class that the other side will receive will always be an ArrayList, although the method will be generated to use the List interface.

o Map - All elements in the Map must be of one of the types in this list, including other AIDL-generated interfaces and parcelables. Generic maps, (e.g. of the form Map<String,Integer> are not supported. The actual concrete class that the other side will receive will always be a HashMap, although the method will be generated to use the Map interface.

o CharSequence - This is useful for the CharSequence types used by TextView and other widget objects.

• Other AIDL-generated interfaces, which are always passed by reference. An import statement is always needed for these.

• Custom classes that implement the Parcelable protocol and are passed by value. An import statement is always needed for these.

Here is the basic AIDL syntax:

// My AIDL file, named SomeClass.aidl

// Note that standard comment syntax is respected.

// Comments before the import or package statements are not bubbled up // to the generated interface, but comments above interface/method/field // declarations are added to the generated interface.

// Include your fully-qualified package statement, package com.android.sample;

// See the list above for which classes need // import statements (hint--most of them) import com.android.sample.IAtmService;

// Declare the interface, interface IBankAccountService {

// Methods can take 0 or more parameters, and // return a value or void, int getAccountBalance();

void setOwnerNames(in List<String> names);

// Methods can even take other AIDL-defined parameters.

BankAccount createAccount(in String name, int startingDeposit, in IAtmService atmService);

// All non-Java primitive parameters (e.g., int, bool, etc) require // a directional tag indicating which way the data will go. Available // values are in, out, inout. (Primitives are in by default, and cannot be otherwise).

// Limit the direction to what is truly needed, because marshalling parameters // is expensive.

int getCustomerList(in String branch, out String[] customerList);

0 0

Post a comment