zoukankan      html  css  js  c++  java
  • android aidl 进程间通信需要注意的地方(android.os.TransactionTooLargeException)

    转自:http://blog.sina.com.cn/s/blog_4e1e357d0102wau9.html

    1.bus工程实现通过service实现aidl实体类

    2.actor工程通过发起bindservice,根据action去启动远程(跨进程的)bus上的aidl。
     
    那么问题来了,我们知道,linux系统进程间通信,各个进程间资源是隔离的,两个进程间需要通信,就要把msg转换成底层os系统能够识别的数据单元,在Android里面的方案是aidl+parcelbal的序列化。
     
     
    为了模拟和测试aidl的性能问题,我做了个简单实验,在Android中,进程间通信通过binder实现,bind是通信的数据载体,当序列化后的数据单元过大时,就会出问题,报出android.os.TransactionTooLargeException。
     
     
    官方文档里有说明,最大通常限制为1M.也就是说如果大于1M数据的话,就应该分开传。理论上说,应该都是对象和字符串类型的数据为主,只要不是大图片实体等问题,一般应该够用。
    我这边做了一个测试,序列化传送了450k的String被序列化 后的数据,耗时使用了33秒的时间。
     try {
    StringBuilder sb = new StringBuilder();
    for(int i = 0;i< 30;i++){
    sb.append(new String (stringMsg));
    }
    System.out.println( "actor time start :" + System.currentTimeMillis());
    binder.sendMsg("msg from actor : " + sb.toString());
    } catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    ------
     
    public static BusCore coreBinder = new BusCore.Stub() {
     
    @Override
    public void sendMsg(String msg) throws RemoteException {
    Log.d("", " RemoteBusCoreService msg:" + msg);
     
    System.out.println("buscore time end :" + System.currentTimeMillis());
    }
    };
     
     
    对于远程服务,必须调用 bindService()方法,而不是 startService()方法。
     
    今天刚好是在做框架性 实现方案测试时,稍微检测了下个,mark下。
     
    技术讨论,资料分享请加我QQ入群,为了群的干净有秩序,所以有2元入群费要求,群里所收获保证不止2元
     
  • 相关阅读:
    Uniprot Accession的格式以及正则表达式
    python正则表达式统计字符串的个数
    apache开启图片缓存压缩
    mysql之备份表和备份数据库
    linux下lampp的启动和停止脚本
    linux下tomcat的启动,停止,重启脚本
    文件上传PHP
    Assembly测试
    List之Sort使用
    Ienumerable和Ienumerator的使用
  • 原文地址:https://www.cnblogs.com/wangoublog/p/5920062.html
Copyright © 2011-2022 走看看