Skip to content

Instantly share code, notes, and snippets.

@thsaravana
Created March 2, 2020 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thsaravana/d585caa69f9eae876123d36c5c0e095f to your computer and use it in GitHub Desktop.
Save thsaravana/d585caa69f9eae876123d36c5c0e095f to your computer and use it in GitHub Desktop.
To know if App has gone to background or is in foreground
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