I have a class that extends SurfaceView called MapView and a class that I use to update the position on the map called MapUpdater. I would like to be able to inject the MapUpdater class into MapView since it has several dependencies that are also injected with roboguice. However the MapView object is instantiated by the framework and not injected so just trying to inject the MapUpdater just gives me a null value. What is the best way to get a MapUpdater instance that can have objects injected into it?
Asked
Active
Viewed 1,003 times
1 Answers
2
Try using RoboGuice.getInjector(context).getInstance(MapUpdater.class)
.
Or alternately, in your MapView constructor, call RoboGuice.getInjector(context).injectMembers(this)
to manually perform injection on your MapView instance.

emmby
- 99,783
- 65
- 191
- 249
-
Thank you for your response! It worked perfectly. While I have your attention can you point me toward a good book or other document on Guice? The one I have been using "Google Guice: Agile Lightweight Dependency Injection framework" is about 4 years old and I worry that it is a bit out of date. – Shawn Dec 04 '12 at 18:19