isAppOnForeground

protected open fun isAppOnForeground(): Boolean

Checks whether the application is currently running in the foreground.

Use this method to determine if your app is visible to the user when a push notification arrives. This is commonly used in onMessageReceived to decide whether to suppress the system notification and show custom in-app UI instead.

An app is considered "in foreground" when any of its activities is visible and has focus. Example:



protected boolean onMessageReceived(PushMessage message) {
    if (isAppOnForeground()) {
        // App is visible - show in-app notification
        showInAppAlert(message.getMessage());
        return true; // Suppress system notification
    }
    // App is in background - show normal notification
    return false;
}

Return

true if the application is currently visible and has focus, false if the app is in the background or not running

See also