diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java index 41383e528dc3c1..98377c76f7909f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java @@ -86,25 +86,8 @@ public void openURL(String url, Promise promise) { } try { - Activity currentActivity = getCurrentActivity(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url).normalizeScheme()); - - String selfPackageName = getReactApplicationContext().getPackageName(); - ComponentName componentName = - intent.resolveActivity(getReactApplicationContext().getPackageManager()); - String otherPackageName = (componentName != null ? componentName.getPackageName() : ""); - - // If there is no currentActivity or we are launching to a different package we need to set - // the FLAG_ACTIVITY_NEW_TASK flag - if (currentActivity == null || !selfPackageName.equals(otherPackageName)) { - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } - - if (currentActivity != null) { - currentActivity.startActivity(intent); - } else { - getReactApplicationContext().startActivity(intent); - } + sendOSIntent(intent, false); promise.resolve(true); } catch (Exception e) { @@ -235,6 +218,27 @@ public void sendIntent(String action, @Nullable ReadableArray extras, Promise pr } } - getReactApplicationContext().startActivity(intent); + sendOSIntent(intent, true); + } + + private void sendOSIntent(Intent intent, Boolean useNewTaskFlag) { + Activity currentActivity = getCurrentActivity(); + + String selfPackageName = getReactApplicationContext().getPackageName(); + ComponentName componentName = + intent.resolveActivity(getReactApplicationContext().getPackageManager()); + String otherPackageName = (componentName != null ? componentName.getPackageName() : ""); + + // If there is no currentActivity or we are launching to a different package we need to set + // the FLAG_ACTIVITY_NEW_TASK flag + if (useNewTaskFlag || currentActivity == null || !selfPackageName.equals(otherPackageName)) { + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } + + if (currentActivity != null) { + currentActivity.startActivity(intent); + } else { + getReactApplicationContext().startActivity(intent); + } } }