CommunityToolkit / CommunityToolkit/Maui
[BUG] CameraView crashes Android application when going Back too soon
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
### Current Behavior
Hello,
I am facing an issue with the `CameraView ` when capturing an image and the user hits the `Back` button before the callback was handled.
This results in the following exception.
```
**System.NotSupportedException:** 'Unable to activate instance of type CommunityToolkit.Maui.Core.CameraManager+ImageCallBack from native handle 0x79636e2bf8 (key_handle 0x2b0bc91).'
```
If the capture event was handled the `Back` button will not crash the application.
### Expected Behavior
The application should not crash when the exception is thrown.
### Steps To Reproduce
1. Open the `CommunityToolkit.Maui.Sample.sln` solution
2. Start the `CommunityToolkit.Maui.Sample` application on an Android phone.
3. Navigate to `Views`
4. Select the `CameraView Page`
5. Hit the `Capture Image` button and immediately hit the `Back` button in the toolbar.
### Link to public reproduction project repository
https://github.com/CommunityToolkit/Maui/tree/49a124115c6bc09d9ca1ddcdbcc8b425c8ff7479/samples
### Environment
```markdown
- .NET MAUI CommunityToolkit:12.2.0
- OS: Android
- .NET MAUI: 9.x
```
### Anything else?
_No response_
Contributor guide
Research direction
Reproduce the crash from the CommunityToolkit.Maui.Sample.sln on an Android phone by opening the CameraView Page, capturing an image, and immediately using Back. Then inspect the CameraView and CameraManager+ImageCallBack path; done means leaving the page immediately after capture no longer crashes while the capture callback is still pending.
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
- 35/100