【九】注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)
上一篇我们简单的介绍了一下RoboGuice的使用(【八】注入框架RoboGuice使用:(Your
First Injected Fragment)),今天我们来看下服务(Service)和广播接受者(BroadCast Receiver)的注入
(一):和Robo*Activities一样,RoboServices和RoboIntentServices通过RoboGuice也自己主动接受注入。
以下是一个使用RoboGuice注入的android service的样例:
public class MyService extends RoboService {
@Inject ComputeFooModule computeFooModule;
public void onCreate() {
super.onCreate();
//All injections are available from here :
computeFooModule.setUp();
}
public int onStartCommand(Intent intent, int flags, int startId) {
computeFooModule.computeFoo();
return super.onStartCommand();
}
}
RoboGuice也为IntentService提供了注入基类,RoboIntentService。
(二):广播接收者注入
通过RoboGuice ,android BroadCast Receiver也能接受注入。
public class MyBroadcastReceiver extends BroadcastReceiver {
@Inject ComputeFooModule computeFooModule;
protected void handleReceive(Context context, Intent intent) {
//All injections are available from here :
computeFooModule.setUp().computeFoo();
...
}
}
(三):【注意】在RoboGuice中,全部广播接受者能够在整个应用程序范围内接受注入,这就是即使是ContextSingleton在这里也会转成Singleton。
【九】注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)的更多相关文章
- 【八】注入框架RoboGuice使用:(Your First Injected Fragment)
上一篇我们简单的介绍了一下RoboGuice的使用([七]注入框架RoboGuice使用:(Your First Custom Binding)),今天我们来看下fragment的注解 ...
- 【十二】注入框架RoboGuice使用:(Your First Injected ContentProvider)
上一篇我们简单的介绍了一下RoboGuice的使用([十一]注入框架RoboGuice使用:(Your First Injection into a Custom View class)),今天我们来 ...
- 【四】注入框架RoboGuice使用:(Your First System Service Injection)
上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...
- 【十】注入框架RoboGuice使用:(Your First Testcase)
上一篇我们简单的介绍了一下RoboGuice的使用([九]注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)),今天 ...
- 【十三】注入框架RoboGuice采用:(Logging via Ln)
上一篇我们简单的介绍了一下RoboGuice的使用([十二]注入框架RoboGuice使用:(Your First Injected ContentProvider)),今天我们来看下Log日志使用. ...
- 【五】注入框架RoboGuice使用:(Your First POJO Injection)
上一篇我们简单的介绍了一下RoboGuice的使用([四]注入框架RoboGuice使用:(Your First System Service Injection)),今天我们来看下普通Java对象的 ...
- 【十一年】注入框架RoboGuice采用:(Your First Injection into a Custom View class)
上一篇我们简单的介绍了一下RoboGuice的使用([十]注入框架RoboGuice使用:(Your First Testcase)),今天我们来看下自己定义View的注入(Custom View). ...
- 【七】注入框架RoboGuice使用:(Your First Custom Binding)
上一篇我们简单的介绍了一下RoboGuice的使用([六]注入框架RoboGuice使用:(Singletons And ContextSingletons)),今天我们来看下自己定义绑定(bindi ...
- 【三】注入框架RoboGuice使用:(Your First Resource Injection)
上一篇我们简单的介绍了一下RoboGuice的使用([二]注入框架RoboGuice使用:(Your First View Injection)),今天我们来看下资源文件的使用注解的方法: 为了在Ac ...
随机推荐
- FastRPC 3.2 发布,高性能 C++ 协程 RPC 框架
用过go erlang gevent的亲们应该都会知道协程在应用中带来的方便. 如果对协程不理解的同学,通过阅读下面例子可以快速了解我们框架的协程的意义,已了解的可以跳过这部分. 协程例子:假设我们要 ...
- Activitys, Threads, & Memory Leaks
Activitys, Threads, & Memory Leaks 在Android编程中,一个公认的难题是在Activity的生命周期如何协调长期运行的任务和避免有可能出现的内存泄漏问题. ...
- MySQL优化GROUP BY-松散索引扫描与紧凑索引扫描
满足GROUP BY子句的最一般的方法是扫描整个表并创建一个新的临时表,表中每个组的所有行应为连续的,然后使用该临时表来找到组并应用累积函数(如果有).在某些情况中,MySQL能够做得更好,即通过索引 ...
- e = e || window.event用法细节讨论
e = e || window.event是我们在做事件处理时候区分IE和其他浏览器事件对象时常用的写法.但是这行兼容性代码有没有必要出现在所有的事件句柄中呢?标准事件调用方式需要这行代码吗?下边我们 ...
- 微软Code Hunt答案(00-05)——沉迷娱乐的我
昨天看到微软出的网游Code Hunt.o(∩_∩)o...哈哈,还不好好玩一吧,个人感觉不是一个模块比一个模块难的,Code Hunt是按功能划分.所以不要怕自己做不来.由于不同人特长不一样. 像A ...
- 浅谈Oracle数据库性能优化的目标
Oracle性能优化保证了Oracle数据库的健壮性,为了保证Oracle数据库运行在最佳的性能状态下,在信息系统开发之前就应该考虑数据库的优化策略.从数据库性能优化的场景来区分,可以将性能优化分为如 ...
- Idea facet
idea错误:this inspection controls whether the persistence ql queries are error-checked 在project struct ...
- Android GreenDao with Android Studio IDE
转:http://blog.surecase.eu/using-greendao-with-android-studio-ide/ In this tutorial we will show you ...
- php正则的使用[替换,匹配]
// 隐藏电话的中间四位 echo parseMobile('15836365252'); function parseMobile($mobile, $start = 4, $len = 4){ $ ...
- 64位windows8的 IIS运行32位COM组件报错的解决
浏览时报错如下: Microsoft VBScript 运行时错误 错误 '800a01ad'ActiveX 部件不能创建对象: 'sqlcomp.FileSystemObject'/config.a ...