Last active
September 21, 2017 04:02
-
-
Save shahbazahmed1269/40bf5e10b378bc8359dfdba0c945a111 to your computer and use it in GitHub Desktop.
Part of my 2nd blog post on architecture components and MVVM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Inject | |
ViewModelProvider.Factory mViewModelFactory; | |
// Other fields | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Get the reference of Dagger component from our IssuesApplication class. | |
// This is required by Dagger for field injection. | |
((IssuesApplication) getApplication()).getAppComponent().inject(this); | |
// Pass the injected instance of ViewModelFactory | |
mViewModel = ViewModelProviders.of(this, mViewModelFactory).get(ListIssuesViewModel.class); | |
// other code remains unchanged ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment