Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.