Skip to content

Instantly share code, notes, and snippets.

@Wottrich
Last active May 29, 2020 02:47
Show Gist options
  • Save Wottrich/2bc4ce73cce14b3a6a16b79fd2f538e1 to your computer and use it in GitHub Desktop.
Save Wottrich/2bc4ce73cce14b3a6a16b79fd2f538e1 to your computer and use it in GitHub Desktop.
Init ViewModelProviders with inline function
//BaseActivity
inline fun <reified T : ViewModel> initViewModelProvider() : T {
return ViewModelProviders.of(this)[T::class.java]
}
//Activity
private val viewModel : YourViewModel by lazy {
initViewModelProvider<YourViewModel>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment