Define this in all actions: 1.) Define a static final logical flag named 'check_running mode' 2.) Define (override) the onResume () and onPause () methods in all actions. 3.) Set the value of this falg to "true" in onResume () and "false" in the OnPause () methods, respectively. 4.) Check when you receive a push notification: a. If the falg value is true, this means that the application is in the field, so do nothing in this case b. If the flag value is false, this means that the application is in the background, so you can open the application in this case
NOTE. Falg should be static final, as you can just change it from any activity and access it in your receiver class. Hope this works for you!
1 : static boolean check_running mode = false; ------------------- 2: @Override protected void onResume() { super.onResume(); check_running mode = true; } @Override protected void onPause() { check_running mode = false; super.onPause(); } --------------------- 3 : if (check_running mode) { showUserView(); } else { showNotification(); }
source share