Home > Net >  onActivityResult called immediately on startActivityForResult
onActivityResult called immediately on startActivityForResult

Time:04-13

I am trying to get results from native activity in React Native Module. When I called startActivityForResult from my React Native Module, onActivityResult is called immediately even though the activity shows up but RESULT_CANCELED is immediately returned to onActivityResult().

I have followed the official guide from here

My Module code to start activity:

Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
    Intent tgIntent = new Intent(currentActivity, SecondActivity.class);
    tgIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
    currentActivity.startActivityForResult(tgIntent, REQUEST_CODE_ENROLLMENT);
}

I tried both of following to set activity event listener but nothing changes

context.addActivityEventListener(activityEventListener);
context.addActivityEventListener(this);

CodePudding user response:

Remove the "New Task" flag from the intent.

startActivityForResult must be under the same task as the calling activity.

According to documentation:

if the activity you are launching uses Intent#FLAG_ACTIVITY_NEW_TASK, it will not run in your task and thus you will immediately receive a cancel result.

  • Related