【九】注入框架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 ...
随机推荐
- fragment中listview触发事件setOnItemClickListener不好使
<listView/>中// listview点击 ,高度wrap_content改成fill_prarent
- android对应版本号
android对应版本号 Platform Version API Level VERSION_CODE Notes Android 4.2 JELLY_BEAN_MR1 Platform Highl ...
- 微信公众帐号开发。大家是用框架还是自己写的流程。现在遇到若干问题。请教各路大仙 - V2EX
微信公众帐号开发.大家是用框架还是自己写的流程.现在遇到若干问题.请教各路大仙 - V2EX 微信公众帐号开发.大家是用框架还是自己写的流程.现在遇到若干问题.请教各路大仙
- S3C2440实现wifi、3G上网和迷你无线路由的制作(一)
S3C2440实现wifi.3G上网和迷你无线路由的制作 fulinux 凌云实验室 本文将通过ARM.linux平台,借助RT2070/RT3070芯片的无线模块(或使用RT2070/RT3070芯 ...
- IOS学习笔记06---C语言函数
IOS学习笔记06---C语言函数 -------------------------------------------- qq交流群:创梦技术交流群:251572072 ...
- 使用Vitamio打造自己的Android万能播放器(4)——本地播放(快捷搜索、数据存储)
前言 关键字:Vitamio.VPlayer.Android播放器.Android影音.Android开源播放器 本章节把Android万能播放器本地播放的主要功能(缓存播放列表和A-Z快速查询功能) ...
- oracle&&Sqlserver获取表名列名主键及数据类型
SQlserver获得列名,列类型,列类型长度,scale,prec等数据类型(syscolumns,systypes,sysobjects均为视图) select a.name as colname ...
- 第10课_dg
export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE ...
- log4j日志输出配置
# Configure logging for testing: optionally with log filelog4j.rootLogger=WARN, stdoutlog4j.rootLogg ...
- -bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory
刚刚学习SHELL 写了一个简单的例子发生如下错误 -bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory ...