Android checking whether the app is closed

This answer uses ProcessLifecycleOwner to detect application visibility. which is a part of Android Architecture Component . 1. add this lib to your project implementation “android.arch.lifecycle:extensions:1.1.1” 2. Extend an application class that implements LifecycleObserver public class AppController extends Application implements LifecycleObserver { /////////////////////////////////////////////// @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onEnterForeground() { Log.d(“AppController”, “Foreground”); isAppInBackground(false); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void … Read more