dotnet / dotnet/android-libraries

ActivityResultLauncher and RegisterForActivityResult

Open
#289 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
317
Forks
73
Avg merge
1d 8h
Merged PRs (30d)
17

Description

VS 16.10.0 P1.0

I recently upgraded Xamarin.AndroidX.AppCompat from 1.2.0.6 to 1.2.0.7
and Xamarin.AndroidX.Fragment from 1.2.5.4 to 1.3.0.1

This resulted in warnings re StartActivityForResult being deprecated in some of my Fragments. Then I noticed in my MainActivity (single Activity app) that there was one that didn't have a warning. This seems inconsistent, so I'm asking if that is expected and just a difference between Activity and Fragment or should it also be marked as obsolete/deprecated in Activity.

I reworked my code in the MainActivty to use the new ActivityResultLauncher and that worked ok. However, the IActivityResultCallback results in public void OnActivityResult(Java.Lang.Object p0) which leads to some pretty ugly code having to test and cast the p0 to whatever is needed before you can use it. The old way was at least readable!! The fragments now all use the new ActivityResultLauncher so they are ok as well.

I then tried a couple of variations of the other types of ActivtyResultContracts as tests in a test project. Some worked, some didn't. GetContent() works, but TakePicture() wouldn't return a bitmap. I think that is because of what was raised in Issue #288.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.