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

Session initialization already happened

Open djrausch opened this issue 5 years ago • 9 comments

Hi,

Our Branch implementation has stopped working once updating from 4.0.0 to 4.3.2. We had a splash activity that launched a Main activity and the app was then a single activity app. I refactored our code to include splash in our nav graph and have a true single activity app thinking this may be part of the issue. Turns out the issue still exists.

I have followed to docs exactly, yet the Branch listener gets an error (issue title) on returning to the app (it works fine if the app is not in memory). The docs state that I am to put Branch.getInstance().initSession(branchListener, this.intent.data, this) in my onStart. That's fine, but when the activity is resumed, onStart is called again. Because of this I get no data sent to my Branch listener. However, if I kill the app and reopen the intended data flows through.

I also have

this.intent = intent
Branch.getInstance().reInitSession(this, branchListener)

in my onNewIntent()

I tried moving the initSession call to onCreate as that is only called once, but then I get initializing session on user's behalf (onActivityResumed called but SESSION_STATE = UNINITIALISED)

Any ideas? Thanks!

djrausch avatar Feb 13 '20 17:02 djrausch

  @Override
    public void onNewIntent(Intent intent) {
        this.setIntent(intent);
    }

have you tried this ^ without reInitSession?

jliu-branch avatar Feb 14 '20 08:02 jliu-branch

Just tried that and same result.

I did notice something interesting. When I open a branch link with the app in memory, it won't pass the params. However, if I kill the app and re-open the params are then passed.

djrausch avatar Feb 14 '20 17:02 djrausch

Have the same problem after update from 4.1.1 to 4.3.2. Deeplink from Google Play install doesn't work if application contains SplashActivity. If I remove SplashActivity, deeplink start to work fine, but I need to have SplashActivity.

Taharo avatar Feb 18 '20 13:02 Taharo

Hi,

I am facing the same issue. Did you find any solution?

Thanks.

FaisalAli19 avatar Mar 31 '20 08:03 FaisalAli19

Hi all, we are having internal discussions about how to best approach this scenario. In the short term, there is a workaround that simply reverts the SDK behavior to pre v4.2.0 (to be placed in the initSession callback)

// client's code
if (error == null && referringParams != null) {
  branchReferringPramas_ = referringParams.toString()
}
// the workaround for the ERR_BRANCH_ALREADY_INITIALIZED error
if else (error.getErrorCode() == BranchError.ERR_BRANCH_ALREADY_INITIALIZED) {
  
branchReferringPramas_ = Branch.getLatestReferringParams();

}

There is more information here about how to avoid this error the proper way.

bklastaitis-branch avatar Apr 03 '20 07:04 bklastaitis-branch

Sup

FWIW this worked for me: I REMOVED this line from their documentation

 @Override
      public void onNewIntent(Intent intent) {
          super.onNewIntent(intent);
          RNBranchModule.onNewIntent(intent); // Remove this line
      }

And replaced it with this:

 @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent); // Added this one 

     // Idk if you actually need this but it was in there when it worked
      if(intent != null) {
          intent.putExtra("branch_force_new_session", true);
      }
    }

connoremma avatar Dec 18 '20 01:12 connoremma

The same happened to me and nothing seemed to help, then I saw that the Branch tutorial was quite confusing - you need the call Branch.getAutoInstance(this) on the Applications onCreate, not the Splash/other branch receiving activity. Moving it there has solved this issue.

daviduzan avatar Dec 21 '21 07:12 daviduzan