网站大量收购独家精品文档,联系QQ:2885784924

第7章 后台服务.ppt

  1. 1、本文档共136页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
7.3 远程服务 7.3.3 数据传递 AllResult.java的完整代码 31 @Override 32 public void writeToParcel(Parcel dest, int flags) { 33 dest.writeLong(AddResult); 34 dest.writeLong(SubResult); 35 dest.writeLong(MulResult); 36 dest.writeDouble(DivResult); 37 } 38 39 public static final Parcelable.CreatorAllResult CREATOR = 40 new Parcelable.CreatorAllResult(){ 41 public AllResult createFromParcel(Parcel parcel){ 42 return new AllResult(parcel); 7.3 远程服务 7.3.3 数据传递 AllResult.java的完整代码 43 } 44 public AllResult[] newArray(int size){ 45 return new AllResult[size]; 46 } 47 }; 48 } 7.3 远程服务 7.3.3 数据传递 代码第6行说明了AllResult类继承于Parcelable 代码第7行到第10行用来保存全运算的运算结果 第12行是AllResult类的基本构造函数 第19行也是类的构造函数,支持Parcel对象实例化AllResult 代码第32行的writeToParcel()是“打包”函数,将AllResult类内部的数据,按照特定的顺序写入Parcel对象,写入的顺序必须与构造函数的读取顺序一致(代码第20行到第23行) 第39行实现了静态公共字段Creator,用来使用Parcel对象构造AllResult对象 7.3 远程服务 7.3.3 数据传递 在MathService.java文件中,增加了用来进行全运算的ComputAll()函数,并将运算结果保存在AllResult对象中 MathService.java中的ComputAll()函数实现代码如下 1 @Override 2 public AllResult ComputeAll(long a, long b) throws RemoteException { 3 long addRusult = a + b; 4 long subResult = a - b; 5 long mulResult = a * b; 6 double divResult = (double) a / (double)b; 7 AllResult allResult = new AllResult(addRusult, subResult, mulResult, divResult); 8 return allResult; 9 } 7.3 远程服务 7.3.3 数据传递 ParcelMathCallerDemo示例是ParcelMathServiceDemo示例中MathService服务的调用 ParcelMathCallerDemo文件结构如右图所示 其中,AllResult.aidl、AllResult.java和IMathService.aidl文件务必与ParcelMathServiceDemo示例的三个文件完全一致,否则会出现错误 7.3 远程服务 7.3.3 数据传递 下图是ParcelMathCallerDemo用户界面 7.3 远程服务 7.3.3 数据传递 上图的ParcelMathCallerDemo界面中可以发现,原来的“加法运算”按钮改为了“全运算”按钮,运算结果显示在界面的上方 下面也仅给出ParcelMathCallerDemo.java文件与RemoteMathCallerDemo示例RemoteMathCallerDemoActivity.java文件不同的代码段 定义了“全运算”按钮的监听函数 随机产生输入值 调用远程服务 获取运算结果,并将运算结果显示在

文档评论(0)

yaocen + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档