使用AIDL将接口暴露给客户端(远程绑定Service)
import java.util.Timer;
import java.util.TimerTask;
import jww.mediaprovidertest.ICat.Stub;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
public class AidlService extends Service{
private CatBinder catBinder;
Timer timer = new Timer();
String[] colors = new String[]{
"红色","黄色","黑色"
};
double[] weights = new double[]{
2.3 , 3.1 ,1.58
};
private String color;
private double weight;
//继承Stub,也就是实现了ICat接口,并实现了IBinder接口
public class CatBinder extends Stub{
@Override
public String getColor() throws RemoteException {
return color;
}
@Override
public double getWeight() throws RemoteException {
return weight;
}
}
@Override
public void onCreate() {
super.onCreate();
catBinder = new CatBinder();
timer.schedule(new TimerTask() {
@Override
public void run() {
// 随即地改变Service组件内color、weight属性的值
int rand = (int)(Math.random()*3);
color = colors[rand];
weight = weights[rand];
System.out.println("------"+rand);
}
}, 0 ,800);
}
@Override
public IBinder onBind(Intent intent) {
/*
* 返回catBinder对象
* 在绑定本地Service的情况下,该catBinder对象会直接
* 传给客户端的ServiceConnection对象
* 的onServiceConnected方法的第二个参数
* 在绑定远程Service的情况下,只将catBinder对象的代理
* 传给客户端的ServiceConnection对象
* 的onServiceConnected方法的第二个参数
*/
return catBinder;
}
@Override
public void onDestroy() {
timer.cancel();
}
}
使用AIDL将接口暴露给客户端(远程绑定Service)的更多相关文章
- 客户端访问AIDLService(远程绑定Service)
import android.os.Bundle;import android.os.IBinder;import android.os.RemoteException;import android. ...
- AIDL —— Android接口定义语言
AIDL:Android Interface Definition Language,即Android接口定义语言,是Android进程间通信比较常用的一种方式.翻译一下,就是为了让某个Service ...
- 几种远程调用接口协议简单比较和web service(SOAP)与HTTP接口的区别:
什么是web service? 答:soap请求是HTTP POST的一个专用版本,遵循一种特殊的xml消息格式Content-type设置为: text/xml任何数据都可以xml化. ...
- AIDL安卓接口定义语言
Android Interface Definition Language简称AIDL翻译为 :安卓 接口 定义 语言 AIDL:进程间通信.Android ...
- WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误
WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while ...
- ems lite 客户端远程连接mysql server
在本地用ems客户端远程连接虚拟机上的mysql server,弹出客户端没有权限访问mysql server.使用下面方法进行设置:mysql> select host,user,passwo ...
- SQLServer 2005客户端远程连接sql2008 数据库服务器
SQL2005客户端远程连接sql2008 数据库服务器 by:授客 QQ:1033553122 准备工作: 客户端所在pc机配置: 配置数据源 控制面板-管理工具-ODBC数据源-系统DSN-添加- ...
- (转)SqlServer2008开启客户端远程连接
原文地址:http://wenku.baidu.com/link?url=MiiJG0SKUUAb3kzrrQtdx0zGIDpsGa7vcGlzqIDe7qcFx5NJ4UlVoPIswxZCHMo ...
- 客户端远程调用Feign
客户端远程调用 Feign 什么是Feign? Feign是 Netflix 公司开源的声明式HTTP客户端 Github : Feign 源码 为什么需要Feign? 原代码可读性不高 复杂的URL ...
随机推荐
- iOS - Delegate 代理
1.Delegate 1.1 协议 协议:是多个类共享的一个方法列表.协议中列出的方法没有相应的实现,计划由其他人来实现.协议中列出的方法,有些是可以选择实现,有些是必须实现. 1>.如果你定义 ...
- iOS - UINavigationController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController @available(iOS 2 ...
- iOS - UIDatePicker
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIDatePicker : UIControl <NSCoding> ...
- iOS - UIWebView
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIWebView : UIView <NSCoding, UIScrol ...
- mysql概要(四)order by,group 的特点,子查询
1.order by 默认按升序排列(asc/desc),多字段排序 order by 字段 排序方式,字段2 排序方式,..:在分组排序中,排序是对分组后的结局进行排序,而不是在组中进行排序. 2. ...
- 禁止ubuntu的super快捷键
在mac上安装了ubuntu虚拟机, 但是发现command健(ubuntu中叫super健)被系统占用了, 习惯了command健的同学来说非常不方便, 如何禁用默认的command健呢? You ...
- [转载] C++ 多线程编程总结
原文: http://www.cnblogs.com/zhiranok/archive/2012/05/13/cpp_multi_thread.html 在开发C++程序时,一般在吞吐量.并发.实时性 ...
- mysql Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
错误原因:/var/lib/mysql目录中socket文件不存在.连接mysql服务器有两种方式:tcp连接,通过socket文件连接.通过socket文件,启动mysql服务,mysql服务会自动 ...
- nginx相关优化
1.配置监控nginx状态信息 vim /usr/locale/nginx/conf/nginx.conf server { listen ; server_name 192.168.1.30; lo ...
- onTouch事件试验(覆写onTouchEvent方法,同时设置onTouchListener)
xml布局文件 <</span>RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...