0

I have a problem with Dagger2 singleton annotation. My module looks a bit like this:

@Module
public class MyModule {
    @Singleton
    @Provides
    MyInterface provideSipManager(Context context) {
        Log.d("running provider");
        return new MyClass(context);
    }
}

Component is similar to:

@Component(modules = {ApplicationModule.class, MyModule.class})
@Singleton
public interface ApplicationComponent {
    Context context();
    void inject(MyApplication application);
    void inject(Myactivity1 myActivity);
    void inject(Myactivity2 myActivity);
}

The problem is that everytime I inject MyInterface, I get completely new object. I'm using Singleton annotation, so I should get the same instance. What am I doing wrong?

endriu440
  • 13
  • 4
  • Do you create a new component each time, or create one once and keep it around? The component instance keeps the state, so if you create a new component you'll necessarily create a new instance of each `@Singleton` you request. – Jeff Bowman Feb 21 '17 at 03:27
  • Jeff Bowman You were right, the problem was creating App component multiple times. Thank you. – endriu440 Feb 22 '17 at 12:44

0 Answers0