views:

882

answers:

2

I've been looking around, in vain, for some information on using a dependency injection container in Android development. Specifically, how to override the creation of an Activity in a way that will also work when coming back from being killed (for whatever reason).

Has anyone got any experience in this area?

+5  A: 

It appears you can use Google Guice 2.0 with Android. You might also look into roboguice.

Jay Askren
Thanks, it looks like roboguice is the closest I'm going to get it. It uses inheritance (`GuiceActivity`) and performs injection on `setContentView`, but after checking out the `Activity` creation callstack I can see there's no other way.
Richard Szalay
By the way Richard, RoboGuice now does injection in two steps. Once during onCreate for most injections, and once during setContentView for View injections.
Mike
A: 

You might also want to consider Spring ME. Although originally intended for Java ME, I have seen reports from people using it for Android as well. The benefit would be that you have a familiar programming model (Spring) without the penalty: Spring ME has a 0k footprint.

Wilfred Springer