Skip to content

Instantly share code, notes, and snippets.

@BalazsErik
Created April 29, 2020 06:06
Show Gist options
  • Save BalazsErik/a6f7efbff9689eeabd0a233f937e4b5c to your computer and use it in GitHub Desktop.
Save BalazsErik/a6f7efbff9689eeabd0a233f937e4b5c to your computer and use it in GitHub Desktop.
class LifecycleEventDispatcher(
lifecycleOwner: LifecycleOwner,
val onCreate: () -> Unit = {},
val onStart: () -> Unit = {},
val onResume: () -> Unit = {},
val onPause: () -> Unit = {},
val onStop: () -> Unit = {},
val onDestroy: () -> Unit = {}
) : DefaultLifecycleObserver {
init { lifecycleOwner.lifecycle.addObserver(this) }
override fun onCreate(owner: LifecycleOwner) = onCreate()
override fun onStart(owner: LifecycleOwner) = onStart()
override fun onResume(owner: LifecycleOwner) = onResume()
override fun onPause(owner: LifecycleOwner) = onPause()
override fun onStop(owner: LifecycleOwner) = onStop()
override fun onDestroy(owner: LifecycleOwner) = onDestroy()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment