dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

[Android] Toolbar item icon and text disappears when reopening from recent applications. #24357

Open SergTomcat opened 3 weeks ago

SergTomcat commented 3 weeks ago

Description

Upon returning to foreground, previously drawn ToolbarItems of NavigationPage disappear. Looking at title shifted to the left, buttons are completely removed from layout. Debugger shows that all ToolbarItems present in IList of NavigationPage

Similar bug marked as closed, but definetely repros today (https://github.com/dotnet/maui/issues/11552)

Steps to Reproduce

  1. Add Navigation Page
  2. Add ToolbarItems in constructor of ContentPage
  3. Use android "back" button to put app into backgound.
  4. Return app to foreground
public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();

        ToolbarItems.Add(new(null, "bug", () => { CounterBtn.Text = $"Bugt button clicked"; }));
        ToolbarItems.Add(new(null, "contacts", () => { CounterBtn.Text = $"Person button clicked"; }));
    }
}

Link to public reproduction project repository

https://github.com/SergTomcat/MAUI8_BugDemo2

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 10-14

Did you find any workaround?

Override OnAppearing method of every page with toolbar, clear items and readd them.

protected override void OnAppearing()
{
    base.OnAppearing();

    var tb = ToolbarItems.ToArray();
        ToolbarItems.Clear();
        foreach (var item in tb) 
                ToolbarItems.Add(item);
}

It plugs the hole, but require to be included in everypage, not mentioning additional perfomance overhead.

Relevant log output

No response

github-actions[bot] commented 3 weeks ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

ninachen03 commented 3 weeks ago

This issue has been verified using Visual Studio 17.12.0 Preview 1.0 (8.0.8). Cannot repro on Android platform. bug

SergTomcat commented 3 weeks ago

This issue has been verified using Visual Studio 17.12.0 Preview 1.0 (8.0.8). Cannot repro on Android platform. ![bug]

Tested it on 17.12.0: if you use circle button to put app into backround, it restores normaly. But, if you use back button (◀), app restores without toolbar buttons in layout. Use Android back button. ToolbarItems still contains items, though.

https://github.com/user-attachments/assets/963a1c7e-699e-4de5-8109-ad08fb2d96e5