Skip to content

Commit 3988b8a

Browse files
committed
Move reInitSession into RNBranchModule.onNewIntent.
1 parent e85bd27 commit 3988b8a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ private void generateLocalBroadcast(JSONObject referringParams,
199199
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_LINK_PROPERTIES, linkProperties);
200200
}
201201

202+
/*
203+
* isNewIntent is a capture of the value of mNewIntent above, so does not change when
204+
* mNewIntent changes in onNewIntent.
205+
*/
202206
if (isNewIntent && uri != null) {
203207
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, uri.toString());
204208
}
@@ -215,9 +219,19 @@ private void generateLocalBroadcast(JSONObject referringParams,
215219
Branch.sessionBuilder(reactActivity).withCallback(referralInitListener).withData(uri).init();
216220
}
217221

218-
public static void onNewIntent(@Nonnull Intent intent, @Nonnull Activity activity) {
219-
activity.setIntent(intent);
222+
/**
223+
* Call from Activity.onNewIntent:
224+
* @Override
225+
* public void onNewIntent(Intent intent) {
226+
* super.onNewIntent(intent);
227+
* RNBranchModule.onNewIntent(intent);
228+
* }
229+
* @param intent the new Intent received via Activity.onNewIntent
230+
*/
231+
public static void onNewIntent(@Nonnull Intent intent) {
232+
mActivity.setIntent(intent);
220233
mNewIntent = true;
234+
reInitSession(mActivity);
221235
}
222236

223237
/**
@@ -227,6 +241,10 @@ public static void onNewIntent(@Nonnull Intent intent, @Nonnull Activity activit
227241
* @param uri the URI to include in the notification or null
228242
*/
229243
private static void notifyJSOfInitSessionStart(Context context, Uri uri) {
244+
/*
245+
* This check just ensures that we only generate one RNBranch.initSessionStart
246+
* event per call to onNewIntent().
247+
*/
230248
if (!mNewIntent) return;
231249
mNewIntent = false;
232250

examples/browser_example/android/app/src/main/java/com/browser_example/MainActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ protected void onStart() {
2626
@Override
2727
public void onNewIntent(Intent intent) {
2828
super.onNewIntent(intent);
29-
RNBranchModule.onNewIntent(intent, this);
30-
RNBranchModule.reInitSession(this);
29+
RNBranchModule.onNewIntent(intent);
3130
}
3231
}

examples/testbed_simple/android/app/src/main/java/com/testbed_simple/MainActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ protected void onStart() {
1616
@Override
1717
public void onNewIntent(Intent intent) {
1818
super.onNewIntent(intent);
19-
RNBranchModule.onNewIntent(intent, this);
20-
RNBranchModule.reInitSession(this);
19+
RNBranchModule.onNewIntent(intent);
2120
}
2221

2322
/**

0 commit comments

Comments
 (0)