Skip to content

Instantly share code, notes, and snippets.

@shahbazahmed1269
Last active September 21, 2017 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahbazahmed1269/40bf5e10b378bc8359dfdba0c945a111 to your computer and use it in GitHub Desktop.
Save shahbazahmed1269/40bf5e10b378bc8359dfdba0c945a111 to your computer and use it in GitHub Desktop.
Part of my 2nd blog post on architecture components and MVVM
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