当前位置:  编程技术>移动开发
本页文章导读:
    ▪ViewFlipper除开多余空间        ViewFlipper去掉多余空间 ViewFlipper flipper = (ViewFlipper)findViewById(R.id.flipper); flipper.setMeasureAllChildren(false);  ......
    ▪ Application Fundamentals-Remote procedure calls(远程过程调用)        Application Fundamentals--Remote procedure calls(远程过程调用) Remote procedure calls--远程过程调用Android has a lightweight mechanism for remote procedure calls (RPCs) — where a method is called locally, but executed remotely (in an.........
    ▪ 检察网络wifi       检查网络wifi // check for wifi or 3g ConnectivityManager mgrConn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mgrTel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if ((mgrConn.getA.........

[1]ViewFlipper除开多余空间
    来源: 互联网  发布时间: 2014-02-18
ViewFlipper去掉多余空间

ViewFlipper flipper = (ViewFlipper)findViewById(R.id.flipper); 
flipper.setMeasureAllChildren(false); 


    
[2] Application Fundamentals-Remote procedure calls(远程过程调用)
    来源: 互联网  发布时间: 2014-02-18
Application Fundamentals--Remote procedure calls(远程过程调用)
Remote procedure calls--远程过程调用

Android has a lightweight mechanism for remote procedure calls (RPCs) — where a method is called locally, but executed remotely (in another process), with any result returned back to the caller. This entails decomposing the method call and all its attendant data to a level the operating system can understand, transmitting it from the local process and address space to the remote process and address space, and reassembling and reenacting the call there. Return values have to be transmitted in the opposite direction. Android provides all the code to do that work, so that you can concentrate on defining and implementing the RPC interface itself.

翻译:Android提供了对远程调用(RPC)的轻量级支持--RPC从表面上看是一个本地调用,但是实际是在另外一个进程中执行远程方法,执行结果返回本地调用者。这个过程要求操作系统能够对方法调用、方法参数及返回值具有解析能力;能够把数据对象从本地进程、本地地址空间传递到远程进程、远程地址空间;而且返回值能够逆向传递到本地进程中。所有这些,Android都提供了支持,作为开发者只需要关注远程过程调用(RPC)接口的定义和实现。

An RPC interface can include only methods. By default, all methods are executed synchronously (the local method blocks until the remote method finishes), even if there is no return value.

翻译:RPC接口可以只是包含方法定义,接口中的方法默认都是同步执行(也就是说本地方法的执行需要等待远程方法执行完成方可继续执行,即使远程方法没有返回值。)

In brief, the mechanism works as follows: You'd begin by declaring the RPC interface you want to implement using a simple IDL (interface definition language). From that declaration, the aidl tool generates a Java interface definition that must be made available to both the local and the remote process. It contains two inner class, as shown in the following diagram:

翻译:简单说,实际过程是:开发者先声明RPC接口(使用IDL接口定义语言),然后用aidl 工具生成该接口的Java接口定义,该接口对于本地和远程进程都必须是可见的,这个Java接口中包含两个内部类,如下图所示:


The inner classes have all the code needed to administer remote procedure calls for the interface you declared with the IDL. Both inner classes implement the IBinder interface. One of them is used locally and internally by the system; the code you write can ignore it. The other, called Stub, extends the Binder class. In addition to internal code for effectuating the IPC calls, it contains declarations for the methods in the RPC interface you declared. You would subclass Stub to implement those methods, as indicated in the diagram.

翻译:这两个内部类中提供了所有必要的代码,用于基于你所定义的接口的远程过程调用管理,这两个类都实现了IBinder接口,其中一个内部类用于本地,与操作系统交互。作为远程方法的开发者可以不必考虑它,另外一个内部类也叫Stub(存根),是Binder的子类,该类除了负责RPC调用的相关代码外,还包含RPC接口中所声明的方法声明,开发者应该把这个Stub(存根)类作为基类扩展出子类,在子类中实现接口定义的方法,请参考上图。

Typically, the remote process would be managed by a service (because a service can inform the system about the process and its connections to other processes). It would have both the interface file generated by the aidl tool and the Stub subclass implementing the RPC methods. Clients of the service would have only the interface file generated by the aidl tool.

翻译:通常,远程进程是由一个服务来管理的(因为服务可以向系统通知进程以及和其他进程的连接),这样的服务既包含了aidl工具生成的接口文件也包含远程方法开发者由Stub类扩展出的子类实现的远程方法,使用该服务的客户端代码只需要aidl工具生成的接口文件。

Here's how a connection between a service and its clients is set up:

下面是服务使用方和服务本身之间连接创建的过程:

    * Clients of the service (on the local side) would implement onServiceConnected() and onServiceDisconnected() methods so they can be notified when a successful connection to the remote service is established, and when it goes away. They would then call bindService() to set up the connection.

      翻译:服务客户端 (运行在本地) 需要实现 onServiceConnected() 和 onServiceDisconnected() 方法,这两个方法在与远程服务连接建立完成后或是连接断开时被系统调用。一旦连接建立,onServiceConnected()方法继续调用 bindService() 方法。
   
   * The service's onBind() method would be implemented to either accept or reject the connection, depending on the intent it receives (the intent passed to bindService()). If the connection is accepted, it returns an instance of the Stub subclass.

      翻译:服务的bindService()的作用要么是接受要么是拒绝连接,具体取决于方法的参数intent,如果接受连接,那么该方法返回Stub类的子类实例对象(IBinder接口的实现类)。

    * If the service accepts the connection, Android calls the client's onServiceConnected() method and passes it an IBinder object, a proxy for the Stub subclass managed by the service. Through the proxy, the client can make calls on the remote service.

      翻译:如果服务接受了连接,Android将立刻调用客户端的onServiceConnected()方法,同时为该方法传递一个IBinder对象,这个IBinder对象是一个Stub类的子类代理的概念,由服务负责管理它,借助这个代理实例,客户端就可以对远程服务做调用。

This brief description omits some details of the RPC mechanism. For more information, see Designing a Remote Interface Using AIDL and the IBinder class description.

翻译:以上简要描述的过程中忽视了RPC过程的一些细节,更多信息请查阅Designing a Remote Interface Using AIDL and the IBinder class description.

    
[3] 检察网络wifi
    来源: 互联网  发布时间: 2014-02-18
检查网络wifi

// check for wifi or 3g 
ConnectivityManager mgrConn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
TelephonyManager mgrTel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
if ((mgrConn.getActiveNetworkInfo()!=null && mgrConn.getActiveNetworkInfo().getState()==NetworkInfo.State.CONNECTED) 
       || mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) {  
 ... 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
互联网 iis7站长之家
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3