[Android] Shell and Page.OnBackButtonPressed() not called on root page of Shell tab (Release build)
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 296
Description
### Description
In 10.0.90, Shell.OnBackButtonPressed() is not called when the current page is the root page of a Shell tab on Android. This only happens in Release builds - it works fine in Debug.
### Steps to Reproduce
1. Create a Shell app with multiple tabs.
2. Override Shell.OnBackButtonPressed() so it returns true. eg:
public partial class AppShell : Shell
{
protected override bool OnBackButtonPressed()
{
return true;
}
}
4. Deploy a Release build to Android.
5. Navigate to the root page of a non-home tab.
6. Press the device Back button.
Expected
Shell.OnBackButtonPressed() is called and the event is handled.
Actual
Shell.OnBackButtonPressed() is not called.
Note that the same applies to Page.OnBackButtonPressed().
### Link to public reproduction project repository
_No response_
### Version with bug
10.0.90
### Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
### Last version that worked well
10.0.60
### Affected platforms
Android
### Affected platform versions
_No response_
### Did you find any workaround?
Registering an Android OnBackPressedCallback in MainActivity appears to fix things even if the callback function does nothing except pass the call on to Android. eg.
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
OnBackPressedDispatcher.AddCallback(
this,
new DummyBackPressedCallback());
}
private class DummyBackPressedCallback : OnBackPressedCallback
{
public DummyBackPressedCallback() : base(true)
{
}
public override void HandleOnBackPressed()
{
Enabled = false;
Platform.CurrentActivity?.OnBackPressed();
Enabled = true;
}
}
### Relevant log output
```shell
```
Contributor guide
Research direction
Reproduce the issue in a Shell app with multiple tabs using a Release Android build, focusing on the root page of a non-home tab. Compare Shell.OnBackButtonPressed() and Page.OnBackButtonPressed() with the reported MainActivity OnBackPressedDispatcher workaround; done means the back callback is invoked and handled without requiring that workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100