React-native-branch-deep-linking-attribution: Session initialization already happened

Created on 5 May 2020  路  18Comments  路  Source: BranchMetrics/react-native-branch-deep-linking-attribution

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);
  }
...

鈹斺攢 [email protected]

Most helpful comment

@jpgarcia thanks for reply

yep I do have android:launchMode="singleTask" on the activity so not sure what's up

All 18 comments

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",

166b30b0-c5ad-4f88-8a95-b8169a13fd52

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?

image

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayporta picture jayporta  路  7Comments

thaitanloi365 picture thaitanloi365  路  6Comments

Amurmurmur picture Amurmurmur  路  3Comments

stefanlenoach picture stefanlenoach  路  8Comments

danilobuerger picture danilobuerger  路  7Comments