react-native-screens icon indicating copy to clipboard operation
react-native-screens copied to clipboard

Workaround for restore from background (#17) prevent result of ActivityResultRegistry from working correctly

Open jpcoliveira opened this issue 1 year ago • 2 comments

Description

I'm working on a Brownfield project and I need to interact with native contexts. The problem I'm experiencing is the failure to get activity navigation result using ActivityResultRegistry. Setting savedInstanceState to null in onCreate of the Activity Host prevents the result callback from working correctly.

private val launcher = registerForActivityResult(StartActivityForResult()) { result ->
    ...
}

Below, the workaround for avoid crash when restoring from background (#17), this prevent that other behaviors working in moment of restoring.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
}

In my testing, i notice that onActivityResult is invoked, but this method is deprecated and changed for ActivityResultRegistry.

Base on this fact, does react-native-screens have any perspective of fixing this behavior for mitigate impact in projects that needs use ActivityResultRegistry?

Steps to reproduce

  1. Turn on Don't Keep Activities on your device
  2. Open the app
  3. Click on Navigate to MainActivity 2

Result don't works when returning to the MainActivity

Snack or a link to a repository

https://github.com/jpcoliveira/ActivityRegistrySample

Screens version

3.31.1

React Native version

0.71.6

Platforms

Android

JavaScript runtime

V8

Workflow

None

Architecture

None

Build type

None

Device

Real device

Device model

No response

Acknowledgements

Yes

jpcoliveira avatar Sep 16 '24 18:09 jpcoliveira

@kkafar

jpcoliveira avatar Sep 20 '24 19:09 jpcoliveira

@jpcoliveira we're aware of this issue, as it happens since #17, thus since the very beginnings of the project. This is on our agenda, however currently there items of higher priority. If you have capacity to suggest / develop a solution, any PR is welcome.

kkafar avatar Oct 08 '24 08:10 kkafar