【3】Android AIDL

Android AIDL基本知识点:

(1)Android AIDL 概述

  1. 什么是AIDL
  2. AIDL能实现什么功能

(2)Defining an AIDL Interface 三步

  1. Create the .aidl file
  2. Implement the interface
  3. Expose the interface to clients

(3)AIDL supports data types

  1. 基本类型 such as int, long, char, boolean, and so on
  2. Map、List
  3. CharSequence

(4)Passing Objects over IPC 四步

1.类继承Parcelable 接口
2.实现 writeToParcel 方法
3.添加继承了Parcelable.Creator 的静态成员变量 CREATOR
4.创建AIDL文件,声明创建的parcelable 类

(5)Calling an IPC Method 七步

1.添加AIDL文件
2.声明IBinder接口
3.实现ServiceConnection 接口
4.调用context.bindService方法
5.在onServiceConnected()方法中接收IBinder实例
6.调用在接口中定义的方法
7.调用context.unbindService()断开连接

备注:
1. 跨进程中,对象是被认为引用的
2. 可以把匿名的对象作为方法的参数

参考文档:
(1)、官方GUIDE
(2)、Android:学习AIDL,这一篇文章就够了(上)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章