title: Field not injected in Android Dagger project
body: <p>I am playing with Dagger on Android. I created a model <code>UserPreference</code>, a module called <code>PreferenceModule</code> and another class <code>UserPreferenceTest</code> which is a test of the <code>PreferenceModule</code>. I have below 3 java files</p>
  
  <p>UserPreference.java</p>
  
  <pre><code>package com.sigicn.preference;
  
  import javax.inject.Inject;
  
  import com.sigicn.commonmodels.Application;
  
  public class UserPreference {
      public String name, weiboAccount;
  
      @Inject
      public Application[] frequentlyUsedApps;
  }
  </code></pre>
  
  <p>Then PreferenceModule.java</p>
  
  <pre><code>package com.sigicn.preference;
  
  import javax.inject.Singleton;
  
  import com.sigicn.commonmodels.Application;
  import com.sigicn.utils.MiscUtils;
  
  import dagger.Module;
  import dagger.Provides;
  
  @Module(library = true, complete = true)
  public class PreferenceModule {
  
      @Provides @Singleton UserPreference provideUserPreference() {
          UserPreference userPreference = new UserPreference();
          userPreference.frequentlyUsedApps = provideApplications();
          return userPreference;
      }
  
      @Provides @Singleton Application[] provideApplications() {
          return new Application[]{
                  new Application(
                          MiscUtils.generateUUID(), "Youtube"),
                  new Application(
                          MiscUtils.generateUUID(), "Pixi")
              };
      }
  
  }
  </code></pre>
  
  <p>Then UserPreferenceTest.java</p>
  
  <pre><code>package com.sigicn.test.preference;
  
  import javax.inject.Inject;
  
  import com.sigicn.preference.PreferenceModule;
  import com.sigicn.preference.UserPreference;
  
  import dagger.Module;
  import dagger.ObjectGraph;
  import android.test.AndroidTestCase;
  
  public class UserPreferenceTest extends AndroidTestCase {
      @Module(injects = {UserPreference.class, UserPreferenceTest.class}, 
              includes = PreferenceModule.class)
      static class TestModule {
      }
  
      ObjectGraph objectGraph; 
  
      @Inject
      UserPreference userPreference;
  
      @Override
      protected void setUp() throws Exception {
          if (objectGraph == null) {
              objectGraph = ObjectGraph.create(new TestModule());
          }
          super.setUp();
      }
  
      public void testFrequentlyUsedApps()
      { 
          UserPreference localUserPreference = objectGraph.get(UserPreference.class);
          assertNotNull(localUserPreference);
          assertEquals(localUserPreference.frequentlyUsedApps.length, 2);
  
          objectGraph.inject(this);
          assertNotNull(userPreference);
          assertEquals(userPreference.frequentlyUsedApps.length, 2);
          assertSame(localUserPreference, userPreference);
          assertSame(localUserPreference.frequentlyUsedApps, userPreference.frequentlyUsedApps);
      }
  }
  </code></pre>
  
  <p>But don't know why, that the <code>frequentlyUsedApps</code> of <code>UserPreference</code> is not injected as expected. Any idea why?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I think I have figured out the reason. It's because that I manually create <code>UserPreference</code> and use it in the provider. If I remove the Provider for <code>UserPreference</code>, and let <em>Dagger</em> to wire it automatically, then the field <code>frequentlyUsedApps</code> does get injected. So it is my fault of not understanding <em>Dagger</em> well.</p>