Skip to content

Commit 631258e

Browse files
fix(maui): keep in_foreground true while another window is active
Opening a second window on iPad fires SceneOnResignActivation and SceneDidEnterBackground for the first scene after SceneOnActivated for the second, so InForeground ended up false while the app was in use. Resign and background now leave it true if another connected scene is ForegroundActive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9616a60 commit 631258e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ private static void RegisterMauiEventsBinder(this MauiAppBuilder builder)
128128
lifecycle.SceneOnActivated(scene => SentryMauiEventProcessor.InForeground = true);
129129

130130
lifecycle.DidEnterBackground(application => SentryMauiEventProcessor.InForeground = false);
131-
lifecycle.SceneDidEnterBackground(scene => SentryMauiEventProcessor.InForeground = false);
131+
lifecycle.SceneDidEnterBackground(scene => SentryMauiEventProcessor.InForeground = AnyOtherSceneIsActive(scene));
132132
lifecycle.OnResignActivation(application => SentryMauiEventProcessor.InForeground = false);
133-
lifecycle.SceneOnResignActivation(scene => SentryMauiEventProcessor.InForeground = false);
133+
lifecycle.SceneOnResignActivation(scene => SentryMauiEventProcessor.InForeground = AnyOtherSceneIsActive(scene));
134+
135+
static bool AnyOtherSceneIsActive(UIKit.UIScene scene) =>
136+
UIKit.UIApplication.SharedApplication.ConnectedScenes.ToArray()
137+
.Any(s => s != scene && s.ActivationState == UIKit.UISceneActivationState.ForegroundActive);
134138
});
135139
#elif ANDROID
136140
events.AddAndroid(lifecycle =>

0 commit comments

Comments
 (0)