react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
Session initialization already happened
I have this issue trending on Sentry for my project.
Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.
Example details, its affected around 87 users, 102 events.
Architecture | armeabi-v7a
-- | --
Architectures | [armeabi-v7a, armeabi]
Battery Level | 85%
Boot Time | 2020-04-30T07:28:27Z
Brand | samsung
Connection Type | wifi
Family | SM-J250G
Id | b7c675d870751517
Language | en_NZ
Manufacturer | samsung
Model | SM-J250G (NMF26X)
Name | Galaxy J2 Pro
Online | True
Orientation | portrait
Screen density | 1.5
Screen DPI | 240
Screen height pixels | 960
Screen resolution | 960x540
Screen width pixels | 540
MainApplication.java
...
@Override
public void onCreate() {
super.onCreate();
Intercom.initialize(this, BuildConfig.ANDROID_INTERCOM_API_KEY, BuildConfig.ANDROID_INTERCOM_APP_ID);
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
RNBranchModule.getAutoInstance(this);
}
...
MainActivity.java
...
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(getIntent().getData(), this);
}
...
Are you calling reInitSession
anywhere, e.g. in MainActivity.onResume
? If so, you can remove that.
I'm facing the same error, below is the code for MainActivity.java
` @Override protected void onStart() { super.onStart(); RNBranchModule.initSession(getIntent().getData(), this); }
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); }`
React Native Package :: "react-native-branch": "^4.4.0",
Are you calling reInitSession anywhere, e.g. in MainActivity.onResume? If so, you can remove that.
Getting the same issue, the only two things we have are this (from https://help.branch.io/developers-hub/docs/react-native)
// MainApplication.java
// add onCreate() override
@Override
public void onCreate() {
super.onCreate();
RNBranchModule.getAutoInstance(this);
}
and
// MainActvity.java
@Override
protected void onStart() {
super.onStart();
RNBranchModule.initSession(getIntent().getData(), this);
}
@dozoisch I was facing the same issue here until I realised I was missing the android:launchMode="singleTask"
property on AndroidManifest.xml
Are you including it?
Same issue...in 4.4 (Android only) with singleTask
.
@jpgarcia thanks for reply
yep I do have android:launchMode="singleTask"
on the activity so not sure what's up
Wow, i finally managed to integrate this library within my project and now this is happening. :/
any solution to this? having the same issue. android:launchMode="singleTask"
and no reInitSession
in MainApplication
I have the same problem if i take a picture with react-native-image-crop-picker.
As soon as i select a image i get the error Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.
I also have singleTask and no reInitSession
Still dealing with this. Have singleTask
and no reInitSession
on react-native-branch v5
same problem with expo-branch, singleTask is specified and reInitSession is not called by myself nor the expo-branch. This is breaking deep links for me, as the app crashes and restarts which results in the deep link being lost.
+1
I noticed that reInitSession is called inside RNBranchModule.onNewIntent(intent). on newIntent
Any update on this issue? Did anyone get it to work?
@SteveTro Were you able to find a solution?
I found using react-native-image-crop-picker doesn't trigger onNewIntent() but does trigger onStart() twice.
Android lifecycle https://developer.android.com/guide/components/activities/activity-lifecycle
I found the code below prevented the error but I don't know if it is bad to force a new session onResume().
In MainActivity.java
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
setIntent(intent);
intent.putExtra("branch_force_new_session", true);
}
If you do not need cropping react-native-image-picker doesn't trigger a new branch session
Edit forcing a new session also works onRestart(). But i don't think there is much difference only is onRestart is not called from when the app is closed.
Opening a deeplink from the background. onRestart -> onStart -> onResume -> onNewIntent
Opening a deeplink from closed onCreate -> onStart -> onResume
@Override
protected void onRestart() {
Log.v("Test", "restart");
super.onRestart();
Intent intent = getIntent();
setIntent(intent);
intent.putExtras(this.getIntent());
intent.putExtra("branch_force_new_session", true);
}
@jdee any solution to solve this issue? In our app, we never call reInitSession
and are also experiencing this issue - this prevents deep links from working when the app is running in the background
+1 on this issue, also happens every time we reload the app while debugging. Should we be forcing a new session or not?
This is still happening on Android. I integrated the SDK exactly per the docs. Can anybody from branch weigh in here since this has been open over a year now?
i;m upping this thread, since theres bug i found while using solution from this thread, while the solution works, theres problem if the app is launch from "quick start" which will reinitialize and convey the intent automatically
Still happening for me to. Any work arounds?
We see this issue in our logs as well, but doesn't seem to be causing any problems. Is this causing problems for the rest of you?
Branch sdk is initialising the session on MainActivity start (as per docs), but it only closes a session when all activities are stopped (via the app lifecycle listeners). So if you navigate to a different activity and come back to your MainActivity, onStart
would try to reinitialise a session without the previous one being closed, causing this warning to pop. This is why you see the error when you come back from react-native-image-crop-picker
's cropping Activity. Adding a force_new_session
flag only makes things worse as it'd cause branch to miscount your sessions, bloating your numbers.
I bump this, I believe I have the same problem as @0hio-creator.
My app gets opened by the branch link, then I progress in the funnel up to a point where I'm using image-crop-picker and when the picker is done, I'm sent back to the beginning of the funnel, as if it were the first time. If I then go through the same steps again, it does not happen anymore. In other words: click on branch link -> open app as expected -> pick images -> X app is sent back to "open app as expected" step instead of using the images -> pick images -> use images etc.
If that helps finding out the origin of the issue, I'm also using the @react-navigation/native and stack packages.
Any help would be welcome. I will try @0hio-creator 's suggestions and report back.
Hey @maxime-memtell, without logs I would assume onNewIntent is triggering which is causing Branch to reinitialize. We do suggest to check some conditions before re-initializing branch within onNewIntent: @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent != null && intent.hasExtra("branch_force_new_session") && intent.getBooleanExtra("branch_force_new_session",false)) { RNBranchModule.onNewIntent(intent); } } https://help.branch.io/developers-hub/docs/react-native#android-2