onActivityResult not working in React Native Module with custom Activity

Viewed 164

I want to get the result data from my custom Activity in my React Native Module, but currently, my onActivityResult function never getting that data.

Currently my react module looks like this:

class VideoEditorModule(reactContext: ReactApplicationContext) 
    : ReactContextBaseJavaModule(reactContext), ActivityEventListener {

    ...

    override fun onActivityResult(
        activity: Activity,
        requestCode: Int,
        resultCode: Int,
        data: Intent
    ) {
        val data = data.data

        Log.d("ReactModule", "onActivityResult " + data.toString())
    }

   override fun onNewIntent(intent: Intent?) {
    val data = intent?.data
    Log.d("ReactModule", "onNewIntent: " + data.toString())
   }

   @ReactMethod
   fun openNativeVideoEditor(videoURL: String, promise: Promise) {
      reactApplicationContext.addActivityEventListener(this)

    val currentActivity = currentActivity;

    if (currentActivity == null) {
        promise.reject("ERROR_ACTIVITY", "Activity doesn't exist");
        return;
    }

    modulePromise = promise
    
    val intent = Intent(currentActivity, VideoEditorActivity::class.java)
    intent.putExtra("videoURL", videoURL)
    
    try {
        currentActivity.startActivityForResult(intent, RESULT_OK, null)
    } catch (e: Exception) {
        promise.reject("ERROR_ACTIVITY", e);
        modulePromise = null;
    }
   }

}

The native activity looks like:

class VideoEditorActivity: AppCompatActivity(), OnEditVideoListener {
    ...

    override fun getResult(uri: Uri) {
        Log.d("VideoEditorActivity", "getResult ${uri.path}")

        val i = intent
        i.putExtra("Resulted", uri.path)
        setResult(Activity.RESULT_OK, i)

        finish()
    }
}

Module successfully opens the activity, the activity works, I can edit my video but when I complete my editing, my getResult log prints the new URL for the edited video but looks like the result setup before finish() is not working. onActivityResult in my module doesn't log anything in Android Studio.

Many thanks for each help with this.

RN version 0.64.1

0 Answers
Related