maui: RegisterForActivityResult does not work

Description

RegisterForActivityResult does not work correctly with MauiAppCompatActivity.

I think the issue lies in these two lines:

savedInstanceState?.Remove("android:support:fragments");
savedInstanceState?.Remove("androidx.lifecycle.BundlableSavedStateRegistry.key");

Steps to Reproduce

  1. Clone the repository
  2. Open AndroidApp1.sln
  3. Enable Don't keep activities on Device\Simulator
  4. Add breakpoints in two projects in methods OnActivityResult
  5. Run AndroidApp1
  6. Touch Get result
  7. Choose a contact
  8. Run MauiApp1
  9. Touch Get result
  10. Choose a contact

Link to public reproduction project repository

https://github.com/dimonovdd/RegisterForActivityResult.MAUI

Version with bug

8.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Any

Did you find any workaround?

No response

Relevant log output

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 2
  • Comments: 18 (16 by maintainers)

Most upvoted comments

@dimonovdd it looks like you are supposed to override:

protected virtual bool AllowFragmentRestore => false;

Did that not work for you?

@PureWeen can maybe share details on why we need:

savedInstanceState?.Remove("android:support:fragments");
savedInstanceState?.Remove("androidx.lifecycle.BundlableSavedStateRegistry.key");