Created
March 2, 2020 04:23
-
-
Save thsaravana/d585caa69f9eae876123d36c5c0e095f to your computer and use it in GitHub Desktop.
To know if App has gone to background or is in foreground
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
public class MyApplication implements LifecycleObserver { | |
@Override | |
public void onCreate() { | |
ProcessLifecycleOwner.get().getLifecycle().addObserver(this); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
public void onStart() { | |
Log.d("App in foreground"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
public void onStop() { | |
Log.d("App in background"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment