Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using roboguice without extending Activity

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

like image 695
Vaibhav Mishra Avatar asked Dec 28 '22 13:12

Vaibhav Mishra


1 Answers

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.

like image 124
emmby Avatar answered Jan 10 '23 14:01

emmby