Skip to content

Instantly share code, notes, and snippets.

@smoralb
Created March 31, 2022 19:22
Show Gist options
  • Save smoralb/8e09883714c35ef7e485e106bbeb0a8f to your computer and use it in GitHub Desktop.
Save smoralb/8e09883714c35ef7e485e106bbeb0a8f to your computer and use it in GitHub Desktop.
How a ViewModel can receive a lifecycle event and make some action.
class SampleViewModel : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun initializeCamera() {
if (camera == null) {
getCamera()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment