Question

I'm using AndroidAnnotations in my project and just hooked Dagger + Robolectric + Espresso in.

Currently I have an Activity with SharedPrefences and a class 'injected' by AndroidAnnotations.

public class SomeActivity extends Activity {
  @Pref Prefs_ prefs;
  @Bean SomeManager mManager;
}

Now if I want to use a Dagger to inject these two, what my @Provide methods should look like?

Thank you very much.

Était-ce utile?

La solution

Your @Provide methods should call the getInstance_ method of generated bean classes. This methods creates a new instance and injects the necessary objects. For the generated preference, you should call the constructor new Prefs_(context). However, this is not a too clean way since these generated methods are supposed to called by AA. Also Dagger integration is only working in the snapshot release, check out this thread. But as you can see, you can use Dagger now, but it is not convenient, and it seems to be better to just use AA injection for the AA generated classes for now.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top