【九】注入框架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 ...
随机推荐
- 论山寨手机与Android联姻 【5】MTK颠覆手机产业链
MTK一站式解决方案(Turn-Key)模式出现以前,手机设计开发流程大约可以分成以下6步. 第1步,Design House从芯片厂商那里拿到参考设计. 芯片厂商根据自己的市场部门对手机市场的预测, ...
- HTML5全屏API
现在大多数浏览器都有全屏功能,允许用户来设置或操作.但HTML5的全屏API与之不同,HTML5的全屏API允许web开发工程师在程序中调用. 这样,web开发工程师就可以再网站中设计一个按钮,当该按 ...
- poj 1118 Lining Up(水题)
再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...
- js堆栈溢出错误
function prompt() { var answer = prompt("What is your name","") if (answer) { al ...
- jquery动态连接节点
<1> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- CSS的“层叠”规则的总结
当你随机打开一个页面,查看源代码,你会发现,同一个元素,不止有一个CSS选择器及对应的样式.而一个元素只能应用一个样式,那么一堆样式中究竟是应用哪一个呢?这就涉及到CSS的层叠规则了.下面就来总结下C ...
- mysql 按日期查询
在mysql中,比如你的表的时间字段是column2,并且column2的类型是timestamp 单日查询: select * from TableName where column1='xxxx' ...
- C-JAVA 论坛
http://www.cnblogs.com/lpjia/ JAVA黑马 http://java.itheima.com/java/service/javacourse.shtml
- CentOS 7 +Nginx
一:安装前的准备工作 安装 pcre-devel环境 #yum -y install pcre-devel 安装 openssl 环境 #yum -y install openssl open ...
- Android R.layout. 找不到已存在的布局文件
今天写新页面的时候,突然发现R.layout. 无法找到我已经写好的页面,于是顿时就不淡定了. 把R文件翻了一遍 发现也没有.... 然后我就看到了这个. android.R 原来是我错把Andr ...