在 startActivityForResult 上立即调用 onActivityResult
onActivityResult called immediately on startActivityForResult
我正在尝试从 React Native 模块中的原生 activity 获取结果。当我从我的 React Native 模块调用 startActivityForResult
时,即使 activity 出现,也会立即调用 onActivityResult
,但 RESULT_CANCELED
立即返回到 onActivityResult()。
我已经按照 here
的官方指南进行操作
我要启动的模块代码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);
}
我尝试了以下两种方法来设置 activity 事件侦听器,但没有任何变化
context.addActivityEventListener(activityEventListener);
context.addActivityEventListener(this);
从 intent 中删除“新任务”标志。
startActivityForResult
必须与调用 activity.
在同一任务下
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.
我正在尝试从 React Native 模块中的原生 activity 获取结果。当我从我的 React Native 模块调用 startActivityForResult
时,即使 activity 出现,也会立即调用 onActivityResult
,但 RESULT_CANCELED
立即返回到 onActivityResult()。
我已经按照 here
的官方指南进行操作我要启动的模块代码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);
}
我尝试了以下两种方法来设置 activity 事件侦听器,但没有任何变化
context.addActivityEventListener(activityEventListener);
context.addActivityEventListener(this);
从 intent 中删除“新任务”标志。
startActivityForResult
必须与调用 activity.
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.