Android IPC 系列(2.1):AIDL

原文地址:http://blog.csdn.net/chenfeng0104/article/details/6989217


在上一篇文章(Service使用方式)中,介绍了Android进程间通信(IPC,即不同APP间通信)的使用,并给出了一个示例。但并没有深入分析aidl是怎样可以做到进程间通信的,它的执行过程是怎样的?

这篇文章来分析IRemoteService.aidl的执行过程,并理解aidl是怎样跨进程通信的。

当我们创建IRemoteService.aidl文件时,IDE会为我们在gen目录中创建相应的文件。

[java]   view plain copy print ?
  1. /** This file is auto-generated. DO NOT MODIFY.
  2. * Original file: F:\\workspace\\AndroidImprove\\src\\com\\example\\aidl\\IRemoteService.aidl
  3. */
  4. package com.example.aidl;
  5. public interface IRemoteService extends android.os.IInterface
  6. {
  7. /** Local-side IPC implementation stub class. */
  8. public static abstract class Stub extends android.os.Binder implements com.example.aidl.IRemoteService
  9. {
  10. private static final java.lang.String DESCRIPTOR = "com.example.aidl.IRemoteService";
  11. /** Construct the stub at attach it to the interface. */
  12. public Stub()
  13. {
  14. this.attachInterface(this, DESCRIPTOR);
  15. }
  16. /**
  17. * Cast an IBinder object into an com.example.aidl.IRemoteService interface,
  18. * generating a proxy if needed.
  19. */
  20. public static com.example.aidl.IRemoteService asInterface(android.os.IBinder obj)
  21. {
  22. if ((obj==null)) {
  23. return null;
  24. }
  25. android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
  26. if (((iin!=null)&&(iin instanceof com.example.aidl.IRemoteService))) {
  27. return ((com.example.aidl.IRemoteService)iin);
  28. }
  29. return new com.example.aidl.IRemoteService.Stub.Proxy(obj);
  30. }
  31. public android.os.IBinder asBinder()
  32. {
  33. return this;
  34. }
  35. @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
  36. {
  37. switch (code)
  38. {
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值