Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class BaseActivity extends AppCompatActivity {
  2.  
  3.  
  4. public void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. }
  7.  
  8. public static boolean isAppInFg = false;
  9. public static boolean isScrInFg = false;
  10. public static boolean isChangeScrFg = false;
  11.  
  12. @Override
  13. protected void onStart() {
  14. if (!isAppInFg) {
  15. isAppInFg = true;
  16. isChangeScrFg = false;
  17. onAppStart();
  18. } else {
  19. isChangeScrFg = true;
  20. }
  21. isScrInFg = true;
  22.  
  23. super.onStart();
  24. }
  25.  
  26. @Override
  27. protected void onStop() {
  28. super.onStop();
  29.  
  30. if (!isScrInFg || !isChangeScrFg) {
  31. isAppInFg = false;
  32. onAppPause();
  33. }
  34. isScrInFg = false;
  35. }
  36.  
  37.  
  38. private void onAppStart() {
  39. AlarmReceiver.stopAlarmService(this);
  40. // Toast.makeText(getApplicationContext(), "App in foreground", Toast.LENGTH_LONG).show();
  41. }
  42.  
  43. private void onAppPause() {
  44. AlarmReceiver.startLocalNotificationService(this);
  45. // Toast.makeText(getApplicationContext(), "App in background", Toast.LENGTH_LONG).show();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement