2011-10-02 69 views

回答

10

是的。 1.2-SNAPSHOT尚未進入測試階段,這很容易。要使用1.2,只需將以下代碼添加到onCreate(),onContentChanged()和onDestroy()中。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    RoboGuice.getInjector(this).injectMembersWithoutViews(this); 
    super.onCreate(savedInstanceState); 
} 

@Override 
public void onContentChanged() { 
    super.onContentChanged(); 
    RoboGuice.getInjector(this).injectViewMembers(this); 
} 


@Override 
protected void onDestroy() { 
    try { 
     RoboGuice.destroyInjector(this); 
    } finally { 
     super.onDestroy(); 
    } 
} 

如果您使用RoboGuice 1.1.x版本(最新的穩定版本),那麼其原理是相同的,但如果你不使用roboguice事件你不需要對eventmanager進行的位通話略有不同。看看1.1 RoboActivity source,看看你需要打什麼電話。

+0

我只是去與1.2版本,謝謝。 –

0

它的工作原理,但你必須實現RoboContext和它指向聲明此

protected HashMap<Key<?>,Object> scopedObjects = new HashMap<>();