0

I am using new ActivityResultApi with ReactNavtive.

ReactActivity overrides onActivityResult method.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   mDelegate.onActivityResult(requestCode, resultCode, data);
}

My Fragment code

result = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
         //not getting call back here
    }

How can I get callback back here?

One solution I am working on is calling fragment's onActivityResult method from activity like this

class MainActivity: ReactActivity {
   ... 
   override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    
    val fragment = supportFragmentManager.findFragmentByTag(TAG)
    
    if(fragment is LoadingFragment){
        fragment.onActivityResult(requestCode, resultCode, data)
    }
    
}
   ...

What would be the better approach? How to prevent overriding onActivityResult method in our Activity?

iamanbansal
  • 2,412
  • 2
  • 12
  • 20
  • Looks like the failure to call `super.onActivityResult` in ResultActivity has been fixed in the latest release of the reactive-native library, if that's what you're using. https://github.com/facebook/react-native/commit/29249e19bd9cb4de8cb5b00edcd17f2c49d0d02c#diff-5eeea7cc5d0049418255078dfb3555cdbc3fc02e370392f4b6a31dd831720270 – Tenfour04 Oct 08 '21 at 14:25
  • @Tenfour04 cool! but we can't upgrade RN at the moment. – iamanbansal Oct 08 '21 at 16:39

0 Answers0