MediaPicker - PickPhotosAsync doesn't return on Android when using multiple Activities
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
In net10.0-android apps using multiple activities, PickPhotosAsync does not return when used in a child activity until you return to the main app activity.
The image picker does show and you can select your image, but then it does not return to the calling method.
This used to work until Commit 0c25c62 (https://github.com/dotnet/maui/commit/0c25c624659182fb3e14ef4693a3c5c3ae43cc08) which stops the registration of a new activities against ActivityForResultRequest.
This makes the app wait until the main activity is resumed before the selected image is returned.
This used to work on Android and doing a similar in an iOS app still works.
### Steps to Reproduce
- Create an activity that is not the main Activity.
- Add the implementation for MediaPicker.
- Call PickPhotosAsync and await the Task.
- The picker UI will show.
- Select an image.
- The task will not return until the current activity is closed and the main activity is returned to.
### Link to public reproduction project repository
https://github.com/ben-dean/MediaPicker
### Version with bug
10.0.20
### Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
### Last version that worked well
10.0.11
### Affected platforms
Android
### Affected platform versions
_No response_
### Did you find any workaround?
_No response_
### Relevant log output
```shell
```
Contributor guide
Research direction
Start with the MediaPicker implementation and the ActivityForResultRequest registration changed by commit 0c25c62, then use the linked MediaPicker reproduction to exercise PickPhotosAsync from a child activity. Done means selecting an image completes the awaited task in that child activity without returning to the main activity, while existing Android behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100