A Bug with the Android Back Button in 9.x.x versions
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 296
Description
### Description
The back button in Android doesn't trigger **DispatchKeyEvent** or even the **OnBackPressedDispatcher** if it registers a callback.
### Steps to Reproduce
1. Add latest Microsoft.Maui.Controls package (9.x.x) to a new Maui Blazor project targets .net9
2. Add a new Maui page
3. Add a logic to navigate to that page
```csharp
await App.Current.Windows[0].Navigation.PushModalAsync(new NewPage1());
```
5. Override the DispatchKeyEvent in the MainActivity to capture the back button for example
### Link to public reproduction project repository
https://github.com/abdelrahman-ali-intact/MacrosoftMauiControls9040_Test.git
### Version with bug
9.0.40 SR4
### Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
### Last version that worked well
8.0.100 SR10
### Affected platforms
Android
### Affected platform versions
_No response_
### Did you find any workaround?
No
### Relevant log output
```shell
```
Contributor guide
Research direction
Start with the linked MacrosoftMauiControls9040_Test reproduction and the MainActivity DispatchKeyEvent override, then compare Android back-button behavior in Microsoft.Maui.Controls 9.0.40 SR4 with 8.0.100 SR10. Check how the OnBackPressedDispatcher callback behaves after PushModalAsync; done means the back button reaches the expected handler in the reproduced .NET 9 MAUI Blazor scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100