在用android studio 用AIDL的过程中,AIDL默认支持的数据类型如下(来自android文档):

By default, AIDL supports the following data types:

  • All primitive types in the Java programming language (such as int, long,char, boolean, and so on)
  • String
  • CharSequence
  • List

    All elements in the List must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared. A List may optionally be used as a "generic" class (for example,List). The actual concrete class that the other side receives is always an ArrayList, although the method is generated to use the List interface.

  • Map

    All elements in the Map must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared.  Generic maps, (such as those of the formMap are not supported. The actual concrete class that the other side receives is always a HashMap, although the method is generated to use the Map interface.

You must include an import statement for each additional type not listed above, even if they are defined in the same package as your interface.

如果不是AIDL数据类型,需要自己定义一个新的AIDL文件并实现parcelable接口,示例如下:

 

For example, here is a Rect.aidl file to create a Rect class that's parcelable:

package android.graphics;// Declare Rect so AIDL can find it and knows that it implements// the parcelable protocol.parcelable Rect;

And here is an example of how the Rect class implements theParcelable protocol.

import android.os.Parcel;import android.os.Parcelable;public final class Rect implements Parcelable {

以上两步做完后并不能编译通过,在使用android studio的时候会有类似如下的错误

Error:(5) couldn't find import for class com.XXX.xxx

通过在在android-studio\sdk\platforms\android-19\framework.aidl添加如下内容解决

parcelable com.XXX.xxx;

 

更多相关文章

  1. android jni 调用结构体示例
  2. android浮动搜索框示例
  3. android Menu 选项菜单示例
  4. Android程序示例
  5. android多选ListView示例
  6. Android image的示例 拍照显示
  7. Android 自定义View及其在布局文件中的使用示例
  8. 【Android 内存优化】Bitmap 长图加载 ( BitmapRegionDecoder 简
  9. android Vibrator使用示例

随机推荐

  1. [置顶] 进击的Android注入术《三》
  2. android test frame
  3. Android远程包导入
  4. Unity Android(安卓)SDK 接入(一) - Unit
  5. 探索Android软键盘的疑难杂症
  6. Android真响应式架构——Epoxy的使用
  7. Android必备:Android的体系结构
  8. Android(安卓)RelativeLayout 属性
  9. Android布局优化(三)使用AsyncLayoutInflat
  10. Android(安卓)SDK中tools详解