Skip to content

Commit 217fee9

Browse files
use reInitSession from onNewIntent, so it matches core SDK. Fix intra-app linking from SomeActivity to LauncherActivity where both onNewIntent and onStart get called.
1 parent 67f0035 commit 217fee9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

AdobeBranchExample/src/main/java/io/branch/adobe/demo/ProductActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected void onStart() {
6464
public void onNewIntent(Intent intent) {
6565
super.onNewIntent(intent);
6666
this.setIntent(intent);
67-
AdobeBranch.initSession(branchInitSessionCallback, getIntent().getData(), this, 0);
67+
AdobeBranch.reInitSession(this, branchInitSessionCallback);
6868
}
6969

7070
private void initList() {

AdobeBranchExtension/src/main/java/io/branch/adobe/extension/AdobeBranch.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import io.branch.referral.Branch;
1818
import io.branch.referral.BranchUtil;
19+
import io.branch.referral.Defines;
1920

2021
/**
2122
* AdobeBranch Extension.
@@ -94,6 +95,21 @@ public static boolean initSession(final Branch.BranchReferralInitListener callba
9495
return false;
9596
}
9697

98+
/**
99+
* ReInitialize session. Called from onNewIntent, will only reInitialize if the intent contains a boolean extra "branch_force_new_session"=true
100+
*/
101+
public static boolean reInitSession(@NonNull Activity activity, Branch.BranchReferralInitListener callback) {
102+
Branch branch = Branch.getInstance();
103+
if (branch != null && branch.reInitSession(activity, callback)) {
104+
// this ensures that if user intra-app links from SomeActivity to LauncherActivity,
105+
// and both, initSession and reInitSession, are used in LauncherActivity, then only the
106+
// reInitSession callback returns referring params while the other one returns error, "SDK already initialized".
107+
activity.getIntent().removeExtra(Defines.Jsonkey.ForceNewBranchSession.getKey());
108+
return true;
109+
}
110+
return false;
111+
}
112+
97113
/**
98114
* Register a whitelist of Event Types and Event Sources to send to Branch.
99115
* @param additionalEvents Additional events to listen for.

0 commit comments

Comments
 (0)