Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developer--/dcf544254a1f6aa455f11bad3df68955 to your computer and use it in GitHub Desktop.
Save developer--/dcf544254a1f6aa455f11bad3df68955 to your computer and use it in GitHub Desktop.
public class BaseActivity extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public static boolean isAppInFg = false;
public static boolean isScrInFg = false;
public static boolean isChangeScrFg = false;
@Override
protected void onStart() {
if (!isAppInFg) {
isAppInFg = true;
isChangeScrFg = false;
onAppStart();
} else {
isChangeScrFg = true;
}
isScrInFg = true;
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
if (!isScrInFg || !isChangeScrFg) {
isAppInFg = false;
onAppPause();
}
isScrInFg = false;
}
private void onAppStart() {
AlarmReceiver.stopLocalNotificationService(this);
// Toast.makeText(getApplicationContext(), "App in foreground", Toast.LENGTH_LONG).show();
}
private void onAppPause() {
AlarmReceiver.startLocalNotificationService(this);
// Toast.makeText(getApplicationContext(), "App in background", Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment