上一篇我们简单的介绍了一下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)的更多相关文章

  1. 【八】注入框架RoboGuice使用:(Your First Injected Fragment)

        上一篇我们简单的介绍了一下RoboGuice的使用([七]注入框架RoboGuice使用:(Your First Custom Binding)),今天我们来看下fragment的注解     ...

  2. 【十二】注入框架RoboGuice使用:(Your First Injected ContentProvider)

    上一篇我们简单的介绍了一下RoboGuice的使用([十一]注入框架RoboGuice使用:(Your First Injection into a Custom View class)),今天我们来 ...

  3. 【四】注入框架RoboGuice使用:(Your First System Service Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...

  4. 【十】注入框架RoboGuice使用:(Your First Testcase)

    上一篇我们简单的介绍了一下RoboGuice的使用([九]注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)),今天 ...

  5. 【十三】注入框架RoboGuice采用:(Logging via Ln)

    上一篇我们简单的介绍了一下RoboGuice的使用([十二]注入框架RoboGuice使用:(Your First Injected ContentProvider)),今天我们来看下Log日志使用. ...

  6. 【五】注入框架RoboGuice使用:(Your First POJO Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([四]注入框架RoboGuice使用:(Your First System Service Injection)),今天我们来看下普通Java对象的 ...

  7. 【十一年】注入框架RoboGuice采用:(Your First Injection into a Custom View class)

    上一篇我们简单的介绍了一下RoboGuice的使用([十]注入框架RoboGuice使用:(Your First Testcase)),今天我们来看下自己定义View的注入(Custom View). ...

  8. 【七】注入框架RoboGuice使用:(Your First Custom Binding)

    上一篇我们简单的介绍了一下RoboGuice的使用([六]注入框架RoboGuice使用:(Singletons And ContextSingletons)),今天我们来看下自己定义绑定(bindi ...

  9. 【三】注入框架RoboGuice使用:(Your First Resource Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([二]注入框架RoboGuice使用:(Your First View Injection)),今天我们来看下资源文件的使用注解的方法: 为了在Ac ...

随机推荐

  1. .net c# 正则表达式 平衡组/递归匹配

    原文 http://www.cnblogs.com/qiantuwuliang/archive/2011/06/11/2078482.html 平衡组/递归匹配 这里介绍的平衡组语法是由.Net Fr ...

  2. python map, reduce,filter 使用

    参考python built-on function: http://docs.python.org/2.7/library/functions.html?highlight=map%20reduce ...

  3. 图片文件,图片文件流和BASE64加密字符串之间的转换,以及图片的BASE64加密字符串再jsp上如何显示

    http://blog.csdn.net/sidongxue2/article/details/43036373

  4. POJ——多项式的加法

    1:多项式加法 查看 提交 统计 提问 总时间限制:  1000ms  内存限制:  5000kB 描述 我们经常遇到两多项式相加的情况,在这里,我们就需要用程序来模拟实现把两个多项式相加到一起.首先 ...

  5. html系列教程--header head iframe img

    <head> 标签 用于定义文档的头部,它是所有头部元素的容器.<head> 中的元素可以引用脚本.指示浏览器在哪里找到样式表.提供元信息 head的描述信息包括<bas ...

  6. CentOS启动报错:Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block

    Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block 原因:主要问题就是你更新了内核之后出现的问题. ...

  7. JAVA 可视化分析工具 第12节

    JAVA 可视化分析工具  第12节 经过前几章对堆内存以及垃圾收集机制的学习,相信小伙伴们已经建立了一套比较完整的理论体系!那么这章我们就根据已有的理论知识,通过可视化工具来实践一番. 我们今天要讲 ...

  8. Java提高学习之Object(4)

    哈希码 问: hashCode()方法是用来做什么的? 答: hashCode()方法返回给调用者此对象的哈希码(其值由一个hash函数计算得来).这个方法通常用在基于hash的集合类中,像java. ...

  9. Windows Server 2008 Enterprise使用12G内存

    开启PAE选项,用以下命令解决这个问题: 1.开始运行cmd2.输入 BCDEdit /set PAE forceenable 后回车3.重起系统显示12GB内存,一切正常

  10. JavaWeb核心编程之(三.4)Servlet Context 配置

    ServletContextServlet引擎为每个Web应用程序都创建一个对应的ServletContext对象, ServletContext对象被包含在ServletConfig对象中, 调用S ...