Android AIDL简要介绍及使用

为何要使用AIDL

  1. 什么是AIDL?
    AIDL (Android Interface Definition Language) is similar to other IDLs you might have worked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC).
    根据上述官方文档的说明,AIDL即为android的接口定义语言,跟其它的接口定义语言是类似的。它能够定义约定好的规范的客户端和服务端之间的编程接口,使得进程间能够互相通信。简单来说就是Android上用来实现IPC的一种方式。

  2. 何时选择要使用AIDL?
    Andriod平台上实现IPC的方式有多种,例如:
    非实时性的以通知方式实现简单进程间通信的Intent,Broadcast;
    实时性的Binder/Messenger方式都可以实现IPC

    Note: Using AIDL is necessary only if you allow clients from different applications to access your service for IPC and want to handle multithreading in your service. If you do not need to perform concurrent IPC across different applications, you should create your interface by implementing a Binder or, if you want to perform IPC, but do not need to handle multithreading, implement your interface using a Messenger. Regardless, be sure that you understand Bound Services before implementing an AIDL.
    上述为Android对于AIDL使用的官方提示,即仅当你需要让来自不同应用的多个客户端访问你的service,实现与服务的通信;并且你想要在service内处理多线程。如不是基于这两点需求,建议考虑使用Binder或者Messenger来实现你的进程通信需求。

  3. Android系统使用AIDL的实例简介
    在android平台提供的framework层提供了各种系统服务,最常见的是wifi,bluetooth,sensor等各种设备的管理和使用。常见使用流程为:

NotificationManager mNotificationManager = 
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();

而systemService都是在android

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值