Created
November 17, 2019 19:03
-
-
Save 0phelia/ed44a25c549494d98d72eec6de8b8a61 to your computer and use it in GitHub Desktop.
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
// create observer | |
class ActivityLifecycleObserver: LifecycleObserver { | |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) | |
fun lifecycleResume() { | |
Log.d(MainActivity.TAG, "$this on resume") | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) | |
fun lifecyclePause() { | |
Log.d(MainActivity.TAG, "$this on pause") | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | |
fun lifecycleDestroy() { | |
Log.d(MainActivity.TAG, "$this on destroy") | |
} | |
} | |
// add it to the activity/fragmanet | |
lifecycle.addObserver(ActivityLifecycleObserver()) | |
if (lifeCycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment