質問

Is there a way to use roboguice without extending Activity class with RoboActivity.

役に立ちましたか?

解決

Yes. It's easier with the 1.2-SNAPSHOT which isn't yet in beta. To use 1.2, just add the following to your onCreate(), onContentChanged(), and onDestroy(). You don't need the bits about the EventManager if you're not using roboguice events:

@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();
    }
}

If you're using RoboGuice 1.1.x (the latest stable build), then the principle is the same but the calls are slightly different. Take a look at the 1.1 RoboActivity source to see which calls you need to make.

他のヒント

It works, but you must implement RoboContext and declare this

protected HashMap<Key<?>,Object> scopedObjects = new HashMap<>();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top