上一篇我们简单的介绍了一下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. at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)

    at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333) 原因: null request

  2. Gradient boosting

    Gradient boosting gradient boosting 是一种boosting(组合弱学习器得到强学习器)算法中的一种,可以把学习算法(logistic regression,deci ...

  3. 普林斯顿大学算法课 Algorithm Part I Week 3 快速排序 Quicksort

    发明者:Sir Charles Antony Richard Hoare 基本思想: 先对数据进行洗牌(Shuffle the array) 以数据a[j]为中心进行分区(Partition),使得a ...

  4. Qt部件学习之-烧鹅

    1,布局管理器 candidates

  5. Curious Robin Hood(树状数组+线段树)

    1112 - Curious Robin Hood    PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 ...

  6. hdu 2054 A == B ? (java)

    问题: 考虑问题不周到.没有考虑到可能是小数并且存在 1.0=1.01=1的情况. 本题使用了BigDecimal类,此类适用于高精度的数此时攻克了小数和01=1的问题, 该类比較方式中n.equal ...

  7. sql 查询结果中加入空值列

    select a,b,c,''d from X; 其中d为新加列,''表示默认值为空值 原文:http://hi.baidu.com/ddduggguo/item/747d5ba5ca18fd2689 ...

  8. VS2010中xercesc配置及简单示例

    从官网下载xerces-c-3.1.1并解压,打开工程项目 xerces-c-3.1.1\projects\Win32\VC10\xerces-all\xerces-all.sln, 选择Xerces ...

  9. web开发 - 从零开始 - 01 - 常见样式

    1.width  &  height 2.background : a.background-color b.background-image:url() c.background-repea ...

  10. Oracle EBS Concurrent Request:Gather Schema Statistics[Z]

    Oracle EBS 的Concurrent Request"Gather Schema Statistics"是一个和性能相关的Concurrent Program,它会对表,列 ...