1.AIDL定义

  AIDL是android interface definition language的缩写,它对android IPC组件Binder进行了封装。使用它不需理会底层IPC的实现,只需要简单的定义接口,然后ADT编译生成IPC需要的java文件。极大的方便了开发者和提升了开发的速度及规范。

2.AIDL的使用

  AIDL使用很简单,只需要三个步骤:

  1)接口的定义

  在aidl文件中定义需要给远程调用的接口,它会被ADT自动编译成java文件

  2)接口的实现

  接口定义好了,需要实现接口

     /**
* A secondary interface to the service.
*/
private final ISecondary.Stub mSecondaryBinder = new ISecondary.Stub() {
public int getPid() {
return Process.myPid();
}
public void basicTypes(int anInt, long aLong, boolean aBoolean,
float aFloat, double aDouble, String aString) {
}
};

   实现好接口后,还需要定义Service,实现它的 onBind 方法,然后在onBind方法中将实现的 binder 对象返回,供远程客户端调用。

  3)接口的调用

  首先在客户端绑定远程服务:

 bindService(new Intent(ISecondary.class.getName()),
mSecondaryConnection, Context.BIND_AUTO_CREATE);

  然后实现ServiceConnecton接口,在绑定成功后将远端Service的binder 对象返回:

         /**
* Class for interacting with the secondary interface of the service.
*/
private ServiceConnection mSecondaryConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
// Connecting to a secondary interface is the same as any
// other interface.
mSecondaryService = ISecondary.Stub.asInterface(service);
mKillButton.setEnabled(true);
} public void onServiceDisconnected(ComponentName className) {
mSecondaryService = null;
mKillButton.setEnabled(false);
}
};

  最后直接调用之前定义好的接口即可

AIDL简单使用的更多相关文章

  1. AIDL 简单实现

    实现步骤1.建立一个aidl文件,在里面定义好接口,注意里面不能写public修饰符,同接口一样,包名要一致. package com.systemset.aidl; interface ILight ...

  2. Android的IPC机制(一)——AIDL的使用

    综述 IPC(interprocess communication)是指进程间通信,也就是在两个进程间进行数据交互.不同的操作系统都有他们自己的一套IPC机制.例如在Linux操作系统中可以通过管道. ...

  3. AIDL旅行记之开篇AIDL基本介绍

    嗨,伙伴们,计划了一周的想法最终要在这一刻实现了. 一直都想写一个博客专栏,但是总是鼓不起勇气来写.感觉自己的水量还不太够.哈哈.这次下定决心,与小伙伴们一起分享下Android中的AIDL,从此,也 ...

  4. android跨进程通信(IPC)——AIDL

    转载请标明出处: http://blog.csdn.net/sinat_15877283/article/details/51026711: 本文出自: [温利东的博客] 近期在看 @任玉刚 大神编写 ...

  5. (转载)Android中的Service:Binder,Messenger,AIDL(2)

    前言 前面一篇博文介绍了关于Service的一些基本知识,包括service是什么,怎么创建一个service,创建了一个service之后如何启动它等等.在这一篇博文里有一些需要前一篇铺垫的东西,建 ...

  6. Android艺术开发探索——第二章:IPC机制(下)

    Android艺术开发探索--第二章:IPC机制(下) 我们继续来讲IPC机制,在本篇中你将会学习到 ContentProvider Socket Binder连接池 一.使用ContentProvi ...

  7. Android进程间通信IPC

    一.IPC的说明 IPC是Inter-Process Communication的缩写,含义为进程间通信或跨进程通信,是指两个进程之间进行数据交换的过程. IPC不是Android独有的,任何一个操作 ...

  8. IPC 简说

    IPC(inter-process communication)进程间通信 多进程分为两种情况 1. 同一个应用,使用android:process属性启动的四大组件 2. 多应用 通过android ...

  9. i.mx6 Android5.1.1 vibrator系统服务流程

    0. 概述 0.1 小结 下面来从APP一直分析到kernel的driver,因为vibrator是我所知的最简单的系统服务,分析过程过来,可以获取整个安卓服务的运行思路,把相关知识点都串联起来,又不 ...

随机推荐

  1. 通过java发送http请求

    通常的http请求都是由用户点击某个连接或者按钮来发起的,但是在一些后台的Java程序中需要发送一些get或这post请求,因为不涉及前台页面,该怎么办呢? 下面为大家提供一个Java发送http请求 ...

  2. Java计算日期和时间差

    这篇文章将使用两个例子计算两个日期的时间差.1.使用Java SDK.2.使用Joda库.1.使用Java SDK 计算两个Date之间的时间差,基本思路为把Date转换为ms(微秒),然后计算两个微 ...

  3. xxx-servlet.xml vs applicationContext.xml

    Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml def ...

  4. 使用TopShelf轻松开发Window服务

    关于TopShelf 描述: Topshelf is a framework for hosting services written using the .NET framework. The cr ...

  5. android 关于提高第三方app的service优先级

    本博客仅仅要没有注明"转".那么均为原创,转贴请注明本博客链接链接 基本上大家都知道提高service优先级能够在非常大程度上让你的service免于由于内存不足而被kill,当然 ...

  6. STL中heap算法(堆算法)

     ①push_heap算法 以下是push_heap算法的实现细节.该函数接收两个迭代器,用来表现一个heap底部容器(vector)的头尾,而且新元素已经插入究竟部的最尾端. template ...

  7. [Angular 2] How To Debug An Angular 2 Application - Debugging via Augury or the Console

    In this lesson we will learn several ways to debug an Angular 2 application, including by using Augu ...

  8. mybatis0209 二级缓存

    .1二级缓存 1.1.1原理 mybatis和spring整合后一级缓存就没有了,sqlSession在不关闭的前提下2次查询就会从缓存中取,一级缓存缓存在sqlSession对象里面,当多用户查询的 ...

  9. 配置Windows Live Writer,写cnblogs博客

    引言        以前写博客一般都是联网在cnblogs上面写,不好的地方就是不联网就写不了,当然我们也可以先记录在word文件,等联网在从word里面拷贝出来发布到cnblogs上面,但是样式这些 ...

  10. 小白日记29:kali渗透测试之Web渗透-扫描工具-Vega

    WEB扫描工具-Vega 纯图形化界面,Java编写的开源web扫描器.两种工作模式:扫描模式和代理模式[主流扫描功能].用于爬站.处理表单,注入测试等.支持SSL:http://vega/ca.cr ...