【发布时间】:2016-04-28 12:57:34
【问题描述】:
我发现如果在 Activity 中实例化 Dagger 2 组件,那么它稍后会在 onDestroy() 方法中为空,就像看到的 here 一样。
public class MyActivity {
private MyActivityComponent component;
//...
public void onCreate() {
component = Dagger_MyActivityComponent.builder()
.myApplicationComponent(App.getComponent())
.build()
.inject(this);
//...
}
public void onDestroy() {
component = null;
}
}
如果我不null 那个实例会发生什么?会发生什么?
旁注:in comments 我找到了有用的提示,为什么将其设置为 null,这非常令人信服:“我认为没有必要,但它定义了非常明确的范围”。 em>
【问题讨论】:
标签: android android-activity activity-lifecycle dagger-2