Skip to content

Instantly share code, notes, and snippets.

@motorro
Last active December 25, 2019 05:34
Show Gist options
  • Save motorro/c6ddbc5254f7c3b85a0387f0acd8f7df to your computer and use it in GitHub Desktop.
Save motorro/c6ddbc5254f7c3b85a0387f0acd8f7df to your computer and use it in GitHub Desktop.
ViewModel initialization
abstract class BaseModel: ViewModel() {
var initialized: Boolean = false
private set
/**
* Called from activity's onCreate or onStart
*/
fun initialize() {
if (!initialized) {
doInitialize()
initialized = true
}
}
/**
* Internal initialization (if needed)
*/
protected open fun doInitialize() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment