13

Does anybody know of a way to use Guice to inject dependencies into the constructor of an Activity in Android? It looks like activities normally have only the default constructor so that the platform can easily create a new instance. While it is easy enough to have a singleton to reference the injector and get dependencies that way it is less clean and introduces a bit of static state.

Any suggestions?

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
benstpierre
  • 32,833
  • 51
  • 177
  • 288

1 Answers1

18

I don't know how I missed this!

https://github.com/roboguice/roboguice

Jon Adams
  • 24,464
  • 18
  • 82
  • 120
benstpierre
  • 32,833
  • 51
  • 177
  • 288
  • 1
    Looks cool. Did you use it already? Would you share a bit of your experience with it? – espinchi Nov 20 '10 at 09:52
  • 1
    Can you be more specific about how it is slow please? From the app list using it I'm only able to test geobeagle and I don't feel it slow – eveliotc Nov 24 '10 at 22:38
  • 1
    RoboGuice is not slow at all and used in a whole bunch of successful applications in the Android market. If you have any problems join the mailing list. – Manfred Moser Feb 03 '11 at 18:09
  • 2
    If you're concerned about Java Reflection being slow on some Android devices, give a shot to [AndroidAnnotations](https://github.com/excilys/androidannotations) :) It's a compile time alternative to RoboGuice (which I also like!) – Pierre-Yves Ricau Jan 14 '12 at 15:57