IMediaPicker.CapturePhotoAsync resumes app from splash screen

Bruno Teodori 20 Reputation points
2023-07-20T16:32:17.2266667+00:00

Hi, I've been experiencing this problem in Maui when accessing either CapturePhotoAsync() or PickPhotoAsync(): the app is sent to background either to open the camera or the gallery, once the taken photo or the chosen one are confirmed the app is resumed but it's sent back to its splash screen resulting in the caller method being unable to complete. This happens on Android devices, about 95% of the times on physical device (I'm testing it on a Redmi with android 11.0 api 30), less frequently on emulators (tested both on android 11.0 api 30 and 13.0 api 33).

I can't tell about IOS because I haven't tested it yet.

Here's a sample of my code (that sits in a viewmodel inside a RelayCommand):

1     if (mediaPicker.IsCaptureSupported)
2     {
3	     MainThread.BeginInvokeOnMainThread(async () => {
4		    FileResult chosenPhoto = await mediaPicker.PickPhotoAsync();
5		        	if (chosenPhoto != null)
6			        {
7				      //do something with the picture
8                   }
9                  else
10			        {
11  				     //well something's gone wrong
12			        }
13 	      });
14    }

At line 4 the camera opens, the debugger stops and when i confirm the photo taken or the one picked from the gallery the app doesn't resume where i left but it restarts from its splash screen. Am I doing something wrong here?

I've been struggling with this for a while now and searched all over the internet, but I've found no solution, can anyone help me please?

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Anonymous
    2023-07-28T09:09:37.0066667+00:00

    Hello,

    I guess it's a lack of memory on my own device that's causing the issue.

    Correct, the problem you are experiencing is likely due to limited device memory. To mitigate this issue, it would be advisable to consider using an Android device with a higher memory capacity. This will help ensure smoother performance and accommodate the resource requirements of the application.

    Thank you for your understanding.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.