当前位置: 首页 > news >正文

网站关键词排名seo江门市住房和城乡建设局网站

网站关键词排名seo,江门市住房和城乡建设局网站,网站备案 互联网信息查询,国外低代码平台1.什么是aidl:aidl是 Android Interface definition language的缩写#xff0c;一看就明白#xff0c;它是一种android内部进程通信接口的描述语言#xff0c;通过它我们可以定义进程间的通信接口 icp:interprocess communication :内部进程通信 2.既然aidl可以定义并实现进…1.什么是aidl:aidl是 Android Interface definition language的缩写一看就明白它是一种android内部进程通信接口的描述语言通过它我们可以定义进程间的通信接口 icp:interprocess communication :内部进程通信 2.既然aidl可以定义并实现进程通信那么我们怎么使用它呢文档/android-sdk/docs/guide/developing/tools/aidl.html中对步骤作了详细描述 --1.Create your .aidl file - This file defines an interface (YourInterface.aidl) that defines the methods and fields available to a client. 创建你的aidl文件我在后面给出了一个例子它的aidl文件定义如下写法跟java代码类似但是这里有一点值得注意的就是它可以引用其它aidl文件中定义的接口但是不能够引用你的java类文件中定义的接口 package com.cao.android.demos.binder.aidl; import com.cao.android.demos.binder.aidl.AIDLActivity; interface AIDLService { void registerTestCall(AIDLActivity cb); void invokCallBack(); } --2.Add the .aidl file to your makefile - (the ADT Plugin for Eclipse manages this for you). Android includes the compiler, called AIDL, in the tools/ directory. 编译你的aidl文件这个只要是在eclipse中开发你的adt插件会像资源文件一样把aidl文件编译成java代码生成在gen文件夹下不用手动去编译编译生成AIDLService.java如我例子中代码 --3.Implement your interface methods - The AIDL compiler creates an interface in the Java programming language from your AIDL interface. This interface has an inner abstract class named Stub that inherits the interface (and implements a few additional methods necessary for the IPC call). You must create a class that extends YourInterface.Stub and implements the methods you declared in your .aidl file. 实现你定义aidl接口中的内部抽象类Stub,public static abstract class Stub extends android.os.Binder implements com.cao.android.demos.binder.aidl.AIDLService Stub类继承了Binder并继承我们在aidl文件中定义的接口我们需要实现接口方法下面是我在例子中实现的Stub类 private final AIDLService.Stub mBinder new AIDLService.Stub() { Override public void invokCallBack() throws RemoteException { Log(AIDLService.invokCallBack); Rect1 rect new Rect1(); rect.bottom-1; rect.left-1; rect.right1; rect.top1; callback.performAction(rect); } Override public void registerTestCall(AIDLActivity cb) throws RemoteException { Log(AIDLService.registerTestCall); callback cb; } }; Stub翻译成中文是存根的意思注意Stub对象是在被调用端进程也就是服务端进程,至此服务端aidl服务端得编码完成了。 --4.Expose your interface to clients - If youre writing a service, you should extend Service and override Service.onBind(Intent) to return an instance of your class that implements your interface. 第四步告诉你怎么在客户端如何调用服务端得aidl描述的接口对象doc只告诉我们需要实现Service.onBind(Intent)方法该方法会返回一个IBinder对象到客户端绑定服务时不是需要一个ServiceConnection对象么在没有了解aidl用法前一直不知道它是什么作用其实他就是用来在客户端绑定service时接收service返回的IBinder对象的 AIDLService mService; private ServiceConnection mConnection new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log(connect service); mService AIDLService.Stub.asInterface(service); try { mService.registerTestCall(mCallback); } catch (RemoteException e) { } } public void onServiceDisconnected(ComponentName className) { Log(disconnect service); mService null; } }; mService就是AIDLService对象具体可以看我后面提供的示例代码需要注意在客户端需要存一个服务端实现了的aidl接口描述文件但是客户端只是使用该aidl接口不需要实现它的Stub类获取服务端得aidl对象后mService AIDLService.Stub.asInterface(service);就可以在客户端使用它了对mService对象方法的调用不是在客户端执行而是在服务端执行。 4.aidl中使用java类需要实现Parcelable接口并且在定义类相同包下面对类进行声明 上面我定义了Rect1类 之后你就可以在aidl接口中对该类进行使用了 package com.cao.android.demos.binder.aidl;  import com.cao.android.demos.binder.aidl.Rect1; interface AIDLActivity {       void performAction(in Rect1 rect);   }  注意in/out的说明我这里使用了in表示输入参数out没有试过为什么使用in/out暂时没有做深入研究。 5.aidl使用完整示例为了清除说明aidl使用我这里写了一个例子例子参考了博客: http://blog.csdn.net/saintswordsman/archive/2010/01/04/5130947.aspx 作出说明 例子实现了一个AIDLTestActivityAIDLTestActivity通过bindservice绑定一个服务AIDLTestService通过并获取AIDLTestActivity的一个aidl对象AIDLService该对象提供两个方法一个是registerTestCall注册一个aidl对象通过该方法AIDLTestActivity把本身实现的一个aidl对象AIDLActivity传到AIDLTestService在AIDLTestService通过操作AIDLActivity这个aidl远端对象代理使AIDLTestActivity弹出一个toast完整例子见我上传的资源 http://download.csdn.net/source/3284820
http://wiki.neutronadmin.com/news/453602/

相关文章:

  • vr网站开发如何用云服务器建设网站
  • 怎么样让公司网站软件工程出来干什么工作
  • 陕西做网站网站模版 源码之家
  • 网站开发设计公司wordpress内容模板下载
  • 做网站建设怎么样实用又有创意的设计
  • 气象网站建设管理的不足wordpress不要的代码注释掉
  • 网站建设 投资预算专做美妆的网站
  • 哪家网站专门做折扣销售品牌运动鞋排行榜前十名
  • 企业网站建设策划书范文成都网站建设培训学校
  • 网站内容及内链建设阿里云公司网站制作
  • 网站开发和小程序开发区别职业规划ppt模板免费下载
  • 聚企360做的网站做攻略的网站好
  • 合肥建设网站做网站复杂吗
  • 专业移动微网站设计免费的网站app下载
  • 企业做网站的费用如果做账如何有效提高网站排名
  • 如何根据网址攻击网站自助建站软件公司
  • 文山知名网站建设公司做一个网站赚钱
  • 博客论坛网站开发服装网站建设工作室
  • 网站访问者qqwordpress安装视频
  • 建网站有什么用wordpress 权限
  • 网站下载文件怎么做公司官网包括什么内容
  • 滁州网站建设梦天堂设计公司职位
  • 网站与网站自动跳转代码达州设计公司
  • 长春网站建设招代理手机网站关键词快速排名
  • 找人做网站被骗能立案吗网站怎样做银联支付
  • 私家网站ip地址大全太原优化排名推广
  • 帝国cms获取网站地址wordpress前台不显示
  • 应价交易系统网站开发沈阳网站建设方法
  • 网站建设有什么费用新品发布会海报
  • 郑州网站建设公司 艾特无障碍环境建设 网站