android插件技术-apkplug于OSGI服务基础-08
2015-10-26 11:14
411 查看
我们提供apkplug下OSGI使用demo源代码托管地址为http://git.oschina.net/plug/OSGIService
一OSGI与androidService异同点
OSGI服务与androidService概念差点儿相同也是Service,Client关系。
androidService接口--service.AIDL
OSGI接口--javainterface
所以android进程间通信Service仅仅能传递序列化过的数据而OSGI服务能够传递不论什么java对象。
二OSGI与androidService注冊/查询方式对照
1.服务注冊
androidService
OSGIService
2.服务查询
androidService
OSGIService
三OSGI服务特点
OSGI服务是暂态的插件可能随时被关闭或卸载,所以我们每次在使用服务的时候都最好先查询服务是否还存在。
四OSGI服务注意事项
使用OSGI服务时应注意服务接口java类的一致性,服务者与消费者应使用同样的java接口(类载入器同样),否则可能出现在是时候服务查询类型转换异常。在一般情况下,我们必须提供的服务java介面
一OSGI与androidService异同点
OSGI服务与androidService概念差点儿相同也是Service,Client关系。
androidService接口--service.AIDL
OSGI接口--javainterface
所以android进程间通信Service仅仅能传递序列化过的数据而OSGI服务能够传递不论什么java对象。
二OSGI与androidService注冊/查询方式对照
1.服务注冊
androidService
1 | Intent intent= new Intent(Context,Service. class ); |
2 | Context.startService(intent); |
1 | BundleContext context; //插件上下文 |
2 | ServiceRegistration m_reg=context.registerService( |
3 | sayHelloImp. class .getName(), //服务名称 一般为接口类名 |
4 | my, //服务详细实现类 |
5 | null ); |
androidService
1 | Intent intent= new Intent(Context,Service. class ); |
2 | Context.bindService(intent, new ServiceConnection()) |
3 | ... |
01 | //利用插件上下文BundleContext查询服务 |
02 | ServiceReference class .getName()); |
03 | if (ref null ) { |
04 | //查找到服务 |
05 | Service |
06 | if (service null ) { |
07 | //调用服务接口 |
08 | service.sayHello(imp); |
09 | } |
10 | //注销服务 |
11 | context.ungetService(ref); |
12 | } |
OSGI服务是暂态的插件可能随时被关闭或卸载,所以我们每次在使用服务的时候都最好先查询服务是否还存在。
四OSGI服务注意事项
使用OSGI服务时应注意服务接口java类的一致性,服务者与消费者应使用同样的java接口(类载入器同样),否则可能出现在是时候服务查询类型转换异常。在一般情况下,我们必须提供的服务java介面
相关文章推荐
- android framework中添加自定义的permission
- [Android] Handler源码解析 (Native层)
- Android修改TitleBar标题栏详解
- android Out of memory on a xxx-byte allocation问题
- 在android上实现图像匹配
- Android获取图片大小以及获取指定大小的缩略图
- 【记录】Android html调用Java代码
- Android Hook神器:XPosed入门与登陆劫持演示
- android 通知Notification的使用小实例(振动,灯光,声音)
- Android、Bitmap转Drawable和Drawable转Bitmap
- Android、Bitmap转Drawable和Drawable转Bitmap
- Svn常用操作命令
- 一看就会Android之手机系统音量的设置
- 一看就会Android之手机震动的设置
- android settext刷新其他控件
- Android 中的 Service 全面总结
- android 权限说明——(整理,以后有用)
- android sdk 国内下载更新地址
- android actionBar logo设置不起作用
- android开发could not find class解决方案