Skip to content

Instantly share code, notes, and snippets.

@ceruleanotter
Last active June 20, 2019 19:16
Show Gist options
  • Save ceruleanotter/c41c61142c281c08dcf1bf4391e9abeb to your computer and use it in GitHub Desktop.
Save ceruleanotter/c41c61142c281c08dcf1bf4391e9abeb to your computer and use it in GitHub Desktop.
ViewModel Integrations: NavGraph with a ViewModel Example 4
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Other fragment setup code
NavController navController = NavHostFragment.findNavController(this);
ViewModelProvider viewModelProvider = new ViewModelProvider(this,
navController.getViewModelStore(R.id.checkout_graph));
CheckoutViewModel viewModel = viewModelProvider.get(CheckoutViewModel.class);
// Use Checkout ViewModel
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment