Skip to content

Commit b8bf359

Browse files
committed
Improve Android initialization logic.
1 parent 57b0f9f commit b8bf359

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
8080

8181
private static Activity mActivity = null;
8282
private static boolean mUseDebug = false;
83+
private static boolean mInitialized = false;
8384

8485
private AgingHash<String, BranchUniversalObject> mUniversalObjectMap = new AgingHash<>(AGING_HASH_TTL);
8586

@@ -593,23 +594,17 @@ public static LinkProperties createLinkProperties(ReadableMap linkPropertiesMap,
593594
}
594595

595596
private static Branch setupBranch(Context context) {
596-
Log.i(REACT_CLASS, "Initializing Branch SDK v. " + BuildConfig.VERSION_NAME);
597-
598-
RNBranchConfig config = new RNBranchConfig(context);
599-
String branchKey = config.getBranchKey();
600-
if (branchKey == null) branchKey = config.getUseTestInstance() ? config.getTestKey() : config.getLiveKey();
601-
602-
/*
603-
* This differs a little from iOS. If you add "useTestInstance": true to branch.json but
604-
* don't add the testKey, on iOS, it will use the test key from the Info.plist if configured.
605-
* On Android, useTestInstance in branch.json will be ignored unless testKey is present. If
606-
* testKey is not specified in branch.json, it's necessary to add io.branch.sdk.TestMode to
607-
* the Android manifest to use the test instance. It's not clear if there's a programmatic
608-
* way to select the test key without specifying the key explicitly.
609-
*/
610-
Branch branch = branchKey != null ? Branch.getInstance(context, branchKey) : Branch.getInstance(context);
611-
612-
if (mUseDebug || config.getDebugMode()) branch.setDebug();
597+
Branch branch = Branch.getInstance(context);
598+
599+
if (!mInitialized) {
600+
Log.i(REACT_CLASS, "Initializing Branch SDK v. " + BuildConfig.VERSION_NAME);
601+
602+
RNBranchConfig config = new RNBranchConfig(context);
603+
604+
if (mUseDebug || config.getDebugMode()) branch.setDebug();
605+
606+
mInitialized = true;
607+
}
613608

614609
return branch;
615610
}

0 commit comments

Comments
 (0)