Roboguice가 주입하는 컨텍스트를 알고 싶습니다. 응용 프로그램 컨텍스트 또는 현재 활동입니까?roboguice가 주입 한 컨텍스트는 무엇입니까?
저는 Roboguice와 Robospice를 모두 사용하려고합니다. 프래임에 Robospice의 SpiceManager
을 주입하고 있는데, 프래그먼트가 SpiceManager
에 대해 알지 못한다면 인터페이스를 통해 봅니다. MyInterface
을 봅시다.
public class MyFragment extends RoboFragment {
//this is where the SpiceManager gets injected
@Inject MyInterface manager;
...
}
//this is the implementation that I'm going to inject
//it is simultaneously an event listener for the fragment's life cycle events so that the
//SpiceManager can be appropriately started and stopped.
public class MyManager implements MyInterface {
private SpiceManager spiceManager = new SpiceManager(MySpiceService.class);
//Which context will get injected here? How can I make Roboguice inject a specific context that I want, for example, a specific activity that I want.
private @Inject Context context;
//Here, I need to start the SpiceManager
public void myFragmentOnStart(@Observes OnStartEvent onStart) {
//SpiceManager requires a context, more specifically an activity which will be destroyed and then garbage collected, so It shouldn't be an application context because the resources SpiceManager uses will never be released.
spiceManager.start(context);
}
public void myFragmentOnStop(@Observes OnStopEvent onStop){
if (spiceManager.isStarted()) {
spiceManager.shouldStop();
}
}
}
내 질문은 :
가이 RoboGuice가 활동 이벤트 옆에 조각 이벤트를 관찰 할 수 있으며, 문서는 명확하지 않다?
SpiceManager가 조각/활동이 파괴 될 때 파괴되는 컨텍스트가 필요하다고 생각합니까? SpiceManager.start(Context context)
코드를 살펴본 결과 Context
에 WeakReference
이 생성되었습니다.
RoboGuice가 특정 Context/Activity
을 삽입하도록하려면 어떻게해야합니까?
MyFragment
을 사용하면 MyInterface
개체에 Context
이 필요하다는 것을 알 수 있습니까? 나는 OnStopEvent
이 getActivity()
방법이 있으므로 onStop
에서 Activity
을 받고 아무 문제가 없습니다 만, OnStartEvent
그냥 빈 클래스는 것을 발견 그런데
.