Javier Manzano
Javier Manzano

Reputation: 4821

Injecting with roboguice on non-activity class

Is there any way to inject custom bindings in a class that's not an activity (a class that doesn't extends RoboActivitiy? Because everytime I try to inject it, I get a NullPointerException when accessing it.

I've solved it getting the injector and doing it by myself... but that's something I don't feel comfortable with.

Thanks!

Upvotes: 1

Views: 324

Answers (1)

JRaymond
JRaymond

Reputation: 11782

If the class isn't itself created through injection, then obtaining the injector is the right (and only) way to do it. That's how RoboActivity (see onCreate()) does it in the first place. Objects created through injection get their members Injected by the injector.

Upvotes: 1

Related Questions