Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyApplication extends Application implements LifecycleObserver
- {
- private static Context appContext;
- public static boolean wasInBackground;
- @Override
- public void onCreate()
- {
- super.onCreate();
- appContext=this;
- ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
- }
- public static Context getAppContext() {
- return appContext;
- }
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- public void onMoveToForeground() {
- // app moved to foreground
- wasInBackground=true;
- }
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- public void onMoveToBackground() {
- // app moved to background
- wasInBackground =false;
- }
- }
Add Comment
Please, Sign In to add comment