Skip to content

ActivityResultLauncher and RegisterForActivityResult #289

@gmck

Description

@gmck

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions