diff --git a/src/Android/Avalonia.Android/AvaloniaActivity.cs b/src/Android/Avalonia.Android/AvaloniaActivity.cs index d0538b63046..4e7917494b3 100644 --- a/src/Android/Avalonia.Android/AvaloniaActivity.cs +++ b/src/Android/Avalonia.Android/AvaloniaActivity.cs @@ -122,6 +122,9 @@ protected override void OnResume() { attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges; } + + // We inform the ContentView that it has become visible. OnVisibleChanged() sometimes doesn't get called. Issue #15807. + _view?.OnVisibilityChanged(true); } protected override void OnDestroy() diff --git a/src/Android/Avalonia.Android/AvaloniaView.cs b/src/Android/Avalonia.Android/AvaloniaView.cs index f72da820102..aa5124dcea8 100644 --- a/src/Android/Avalonia.Android/AvaloniaView.cs +++ b/src/Android/Avalonia.Android/AvaloniaView.cs @@ -68,9 +68,9 @@ protected override void OnVisibilityChanged(View changedView, [GeneratedEnum] Vi OnVisibilityChanged(visibility == ViewStates.Visible); } - private void OnVisibilityChanged(bool isVisible) + internal void OnVisibilityChanged(bool isVisible) { - if (isVisible) + if (isVisible && _timerSubscription == null) { if (AvaloniaLocator.Current.GetService() is ChoreographerTimer timer) { @@ -84,10 +84,11 @@ private void OnVisibilityChanged(bool isVisible) (insetsManager as AndroidInsetsManager)?.ApplyStatusBarState(); } } - else + else if (!isVisible && _timerSubscription != null) { _root.StopRendering(); _timerSubscription?.Dispose(); + _timerSubscription = null; } }