Guest User

Untitled

a guest
Jul 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public class MyApplication extends Application implements LifecycleObserver
  2. {
  3. private static Context appContext;
  4. public static boolean wasInBackground;
  5.  
  6. @Override
  7. public void onCreate()
  8. {
  9. super.onCreate();
  10. appContext=this;
  11. ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
  12. }
  13.  
  14. public static Context getAppContext() {
  15. return appContext;
  16. }
  17.  
  18. @OnLifecycleEvent(Lifecycle.Event.ON_START)
  19. public void onMoveToForeground() {
  20. // app moved to foreground
  21. wasInBackground=true;
  22. }
  23.  
  24. @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
  25. public void onMoveToBackground() {
  26. // app moved to background
  27. wasInBackground =false;
  28. }
  29. }
Add Comment
Please, Sign In to add comment