diff --git a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs index b2dbd36c1e6c..a05f44f73db9 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs @@ -86,8 +86,8 @@ public async Task PhotoAsync(MediaPickerOptions options, bool photo, { CompletedHandler = async info => { - GetFileResult(info, tcs); await vc.DismissViewControllerAsync(true); + GetFileResult(info, tcs); } }; diff --git a/src/Essentials/src/Platform/IntermediateActivity.android.cs b/src/Essentials/src/Platform/IntermediateActivity.android.cs index c3b000059fcf..46d44960fba3 100644 --- a/src/Essentials/src/Platform/IntermediateActivity.android.cs +++ b/src/Essentials/src/Platform/IntermediateActivity.android.cs @@ -69,32 +69,32 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int { base.OnActivityResult(requestCode, resultCode, data); - // we have a valid GUID, so handle the task - if (GetIntermediateTask(guid, true) is IntermediateTask task) + var task = GetIntermediateTask(guid, true); + + Finish(); + + if (task is null) + return; + + if (resultCode == Result.Canceled) + { + task.TaskCompletionSource.TrySetCanceled(); + } + else { - if (resultCode == Result.Canceled) + try { - task.TaskCompletionSource.TrySetCanceled(); + data ??= new Intent(); + + task.OnResult?.Invoke(data); + + task.TaskCompletionSource.TrySetResult(data); } - else + catch (Exception ex) { - try - { - data ??= new Intent(); - - task.OnResult?.Invoke(data); - - task.TaskCompletionSource.TrySetResult(data); - } - catch (Exception ex) - { - task.TaskCompletionSource.TrySetException(ex); - } + task.TaskCompletionSource.TrySetException(ex); } } - - // close the intermediate activity - Finish(); } public static Task StartAsync(Intent intent, int requestCode, Action? onCreate = null, Action? onResult = null)