3

I'm new to Roboguice, and I'd like to use it in my new Android application.

I have a test Activity that extends RoboActivity.

public class MainActivity extends RoboActivity {
    @Inject 
    private TestService testService;

    ....        
}

And here is my TestService class:

public class TestService {

    @Inject
    private TestDao testDao;

    @Inject 
    protected static Provider<Context> contextProvider;

    public TestService(){
        Log.d("TEST_SERVICE", "Constructor test");
    }

    public Test getById(Integer id) throws Exception{
        return testDao.queryForId(id);
    }
}

I'm hoping that the @Injected annotated field inside and injected Class will be injected!

TestService is injected by MainActivity. But TestDao is null and also my contextProvider!

I've also defined a roboguice.xml file which defines my IoCModule class:

public class IoCModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(TestDao.class).to(TestDaoOrm.class);
    }
}

I don't know why the inner @Inject won't work!!

Thank you for any suggestion!!

Thank you Marco

gipinani
  • 14,038
  • 12
  • 56
  • 85

1 Answers1

2

I ve solved putting in my modules definition

requestStaticInjection( TestDaoOrm.class );
gipinani
  • 14,038
  • 12
  • 56
  • 85