BpBinder对象如何转换为getService取得的对象的?
来源:互联网 发布:黎明教务网络管理系统 编辑:程序博客网 时间:2024/04/30 23:14
static const android::String16 descriptor; \
static android::sp<I##INTERFACE> asInterface( \
const android::sp<android::IBinder>& obj); \
virtual const android::String16& getInterfaceDescriptor() const; \
I##INTERFACE(); \
virtual ~I##INTERFACE(); \
假定我们的service名称是IMyService。那么以上定义可以转换成如下:
#define DECLARE_META_INTERFACE(MyService)
static const android::String16 descriptor;
static android::sp<IMyService> asInterface(const android::sp<android::IBinder>& obj);
virtual const android::String16& getInterfaceDescriptor() const;
IMyService();
virtual ~IMyService();
#define IMPLEMENT_META_INTERFACE(MyService, my.package)
const android::String16 IMyService::descriptor(my.package.Myservice);
const android::String16& IMyService::getInterfaceDescriptor() const {
return IMyService::descriptor;
}
android::sp<IMyService>IMyService::asInterface( const android::sp<android::IBinder>& obj)
{
android::sp<IMyService> intr;
if (obj != NULL) {
intr = static_cast<IMyService*>( obj->queryLocalInterface( IMyService::descriptor).get()); 这里返回的都是空, BpBinder.cpp文件里面
if (intr == NULL) {
intr = new BpMyService(obj);
}
}
return intr;
}
IMyService::IMyService() { }
IMyService::~IMyService() { }
asInterface传入的对象是BpBinder对象。
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
binder = sm->getService(String16("myService"));
mMyService = interface_cast<IMyService>(binder);
interface_cast调用的就是asInterface。
- BpBinder对象如何转换为getService取得的对象的?
- 如何取得数据库对象的脚本信息
- JS如何取得当前对象的属性
- 浅谈如何安全取得对象的值
- Jquery的容器转换为对象,对象转换为容器
- 取得鼠标所在位置的对象
- 取得鼠标所在位置的对象
- 取得鼠标所在位置的对象
- 如何使用反射取得对象的属性值
- 如何取得ChipmunkConstraint实例对象的私有属性
- 对象数组转换为DataTable的方法
- 转换字符串为json对象的方法
- 转换字符串为json对象的方法
- 转换字符串为json对象的方法
- PHP 对象转换为对应的数组
- 表单的数据转换为json对象
- 对象转换为数组的方法
- 如何将自定义的没有结束标签的xml转换为javabean对象
- 工作的第四个月
- servlet 简单案例!实现图片下载功能
- mysql导出表\mysql导入表
- insertAdjacentHTML方法详解
- 算法2013110102
- BpBinder对象如何转换为getService取得的对象的?
- Android自动检测版本及自动升级
- Mysql5.5 PHP5.4 装PDO_MYSQL 1.0.2模块遇到的问题
- 图的广度优先搜索
- 增加apache支持中文URL
- 如何更改桌面文件夹的的指向
- 连接查询
- 列表页 使用php语句
- 记录Raphael的一点点事