roboguice 1.1.1版本包含对注入上下文的组件的一些基本事件支持.有关详细信息,请参阅http://code.google.com/p/roboguice/wiki/Events.
例如:
@ContextScoped
public class MyObserver {
void handleOnCreate(@Observes OnCreatedEvent e) {
Log.i("MyTag", "onCreated");
}
}
public class MyActivity extends RoboActivity {
@Inject MyObserver observer; // injecting the component here will cause auto-wiring of the handleOnCreate method in the component.
protected void onCreate(Bundle state) {
super.onCreate(state); /* observer.handleOnCreate() will be invoked here */
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3120 次 |
| 最近记录: |