Last active
May 29, 2020 02:47
-
-
Save Wottrich/2bc4ce73cce14b3a6a16b79fd2f538e1 to your computer and use it in GitHub Desktop.
Init ViewModelProviders with inline function
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
//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