【问题标题】:Roboguice is not injecting dependenciesRoboguice 没有注入依赖项
【发布时间】:2015-03-20 15:10:26
【问题描述】:

我正在使用 Roboguice 注入我的依赖项,但它不是 workink。我有一个扩展 RoboActivity 的类,我的属性仍然为空。

public class SplashActivity extends RoboActivity {

    @Inject
    private PropertyReader propertyReader;

    @Inject
    Vibrator v1;

}

我应该做一些额外的配置吗?

提前致谢。

编辑:只有在我有要注入的对象的每个类中都执行 RoboGuice.injectMembers 时,它才有效。我可以为整个应用只做一次吗?

【问题讨论】:

  • 活动是如何创建的?您在哪里访问这些变量(在哪些函数中)?

标签: android roboguice


【解决方案1】:

您应该在活动 onCreate 之后使用注入的非视图字段。 InjectMembers 在 super.onCreate(savedInstanceState) 中运行,您不必调用它。

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   v1.vibrate();
}

应在调用 onCreateView() 后使用视图字段。

【讨论】:

    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多