react-native-branch-deep-linking-attribution icon indicating copy to clipboard operation
react-native-branch-deep-linking-attribution copied to clipboard

Session initialization already happened

Open export-mike opened this issue 4 years ago • 26 comments

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]

export-mike avatar May 05 '20 03:05 export-mike

Are you calling reInitSession anywhere, e.g. in MainActivity.onResume? If so, you can remove that.

jdee avatar May 05 '20 17:05 jdee

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

sandeepsingh91 avatar May 13 '20 04:05 sandeepsingh91

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 avatar Jun 03 '20 21:06 dozoisch

@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

jpgarcia avatar Jun 04 '20 20:06 jpgarcia

Same issue...in 4.4 (Android only) with singleTask.

jamesholcomb avatar Jun 09 '20 20:06 jamesholcomb

@jpgarcia thanks for reply

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

dozoisch avatar Jun 09 '20 21:06 dozoisch

Wow, i finally managed to integrate this library within my project and now this is happening. :/

StarryFire avatar Jul 30 '20 19:07 StarryFire

any solution to this? having the same issue. android:launchMode="singleTask" and no reInitSession in MainApplication

alexsoul95 avatar Sep 07 '20 15:09 alexsoul95

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

SteveTro avatar Oct 22 '20 11:10 SteveTro

Still dealing with this. Have singleTask and no reInitSession on react-native-branch v5

CoryWritesCode avatar Nov 18 '20 18:11 CoryWritesCode

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.

Svarto avatar Dec 01 '20 20:12 Svarto

+1

Seamus1989 avatar Dec 15 '20 13:12 Seamus1989

I noticed that reInitSession is called inside RNBranchModule.onNewIntent(intent). on newIntent

fi-nik avatar Dec 17 '20 01:12 fi-nik

Any update on this issue? Did anyone get it to work?

Svarto avatar Dec 22 '20 09:12 Svarto

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

0hio-creator avatar Jan 31 '21 22:01 0hio-creator

@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

flochtililoch avatar Mar 26 '21 18:03 flochtililoch

+1 on this issue, also happens every time we reload the app while debugging. Should we be forcing a new session or not?

tylerweitzman avatar May 31 '21 22:05 tylerweitzman

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?

evelant avatar Jun 25 '21 17:06 evelant

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

Solid-Metal avatar Sep 06 '21 05:09 Solid-Metal

Still happening for me to. Any work arounds?

dandawson87 avatar Sep 09 '21 14:09 dandawson87

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.

tuncaulubilge avatar Oct 04 '21 09:10 tuncaulubilge

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.

maxime-memtell avatar Mar 07 '22 11:03 maxime-memtell

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

jf-branch avatar Apr 28 '22 15:04 jf-branch