Skip to content

Commit

Permalink
Fix Android app randomly hangs (15807) (#15810)
Browse files Browse the repository at this point in the history
  • Loading branch information
zabolotnev authored and grokys committed Jun 4, 2024
1 parent e3d8f06 commit 068d0c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Android/Avalonia.Android/AvaloniaActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions src/Android/Avalonia.Android/AvaloniaView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRenderTimer>() is ChoreographerTimer timer)
{
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 068d0c1

Please sign in to comment.