鍍金池/ 教程/ Android/ RoboGuice 功能描述
Just-in-time Bindings
Binding Annotations
Standard Injection
第一個(gè)例子 Hello World
Bindings 概述
Linked Bindings
如何綁定 generic 類(lèi)型
@Provides Methods
RoboGuice 功能描述
概述
綜合示例 Astroboy
Inject Resources
Instance Bindings
Inject 自定義 View
Scopes
Provider Bindings
Untargetted Bindings
Inject Extra
第一個(gè)例子 Hello World
Inject Context
發(fā)送接收 Events
Inject View

RoboGuice 功能描述

前面在 Android RoboGuice 使用指南(1):概述 對(duì)應(yīng) Roboguice 做了簡(jiǎn)要的介紹,之后介紹了 Google Guice 的基本用法,Roboguice 是基本 Android 和 Google Guice 開(kāi)發(fā)的適用于 Android 平臺(tái)的 Dependency Injection 開(kāi)發(fā)包,下圖為使用 Roboguice 開(kāi)發(fā)應(yīng)用的基本框圖:

http://wiki.jikexueyuan.com/project/android-roboguice/images/13.png" alt="" />

Android 應(yīng)用程序可以直接使用 Google Guice 來(lái)為普通類(lèi)進(jìn)行注入操作,而對(duì)和 Android 平臺(tái)相關(guān)的類(lèi)如 Activity,Context,Service,View 等可以使用 Roboguice 進(jìn)行注入操作。

在例 Android RoboGuice 使用指南(2):第一個(gè)例子 Hello World 介紹了使用 RoboGuice 開(kāi)發(fā)的步驟,原先從 Activity 派生的類(lèi)一般需要改成從 RoboActivity 派生,并添加從 RoboApplication 派生的類(lèi)作為 Application 應(yīng)用的 Application 類(lèi),詳細(xì)的對(duì)應(yīng)表如下:

http://wiki.jikexueyuan.com/project/android-roboguice/images/14.png" alt="" />

RoboGuice 支持的標(biāo)記如下:

  • @ContextScoped : 表示 Scope 為 Context 范圍 Android RoboGuice 使用指南(11): Scopes
  • @InjectExtra : Intent 的 getExtra 的注入標(biāo)記
  • @InjectPreference: 注入 Preference
  • @InjectResource: 注入 Resource,如 drawable, icon 等
  • @InjectView: 注入 View
  • @Inject: Guice 標(biāo)記,可以注入 Android 平臺(tái)支持的各種服務(wù),比如 LocationManager 等。
  • @SharedPreferencesName: SharedPreferences 名稱(chēng)等

此外,RoboGuice 還提供了簡(jiǎn)單的消息 publish/subscribe 機(jī)制,以及可以支持 Dependency Injection 的 RoboThread, RoboAsyncTask ,RoboLooperThread 等,將在后面的文章詳細(xì)說(shuō)明。