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

Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session",

Open TahaKirmani1 opened this issue 4 years ago • 4 comments

I am getting branch deep link from a push notification. When i get branch deep link from notification, i pass it to the browser, it executes the deep link, and re-opens the app, this time i have branch data, that i use to launch specific screen.

I am using branch 5.0.1

The issue is that i am getting following error message, not every time but most of the times, when opening branch link from push notification. In other cases it just works fine.

_"Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session"

Following is my code.

class SplashActivity : AppCompatActivity(), , Branch.BranchReferralInitListener{

override fun onStart() {
    super.onStart()
     Branch.sessionBuilder(this).withCallback(this).withData(this.intent?.data).init()
}

override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) this.intent = intent Branch.sessionBuilder(this).withCallback(this).reInit() }

override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {

    if (error == null) {

        if(referringParams?.has("news") ==true){
            isNewsItemReceivedFromBranch = true
            branchAggregatedFeedItemId = referringParams.getInt("news")
        }

        initAppStartupProcesses()

    } else {
        initAppStartupProcesses()
    }

}

}

TahaKirmani1 avatar Apr 14 '20 21:04 TahaKirmani1

did you fixed this problem ?

ghost avatar Apr 23 '20 04:04 ghost

As mentioned in #839

I am getting this error when I init Branch in a coroutine on Activity onStart()

uiScope.launch {
    initBranchSession(this, uri)
}

private suspend fun initBranchSession(activity: Activity, uri: Uri?): Uri? {
        return suspendCancellableCoroutine<Uri?> { cont ->
            Branch.sessionBuilder(activity)
                .withCallback { referringParams, error ->
                    if (error != null) {
                        Timber.e("Branch Init error = ${error.message}")
                        cont.resume(null)
                    } else if (referringParams != null) {
                          cont.resume(null)
                    } else {
                        cont.resume(null)
                    }
                }
                .withData(uri)
                .init()
        }
    }

The same seems to work fine if we just remove init from a coroutine. What can be the reason for this behavior.

archie94 avatar Oct 06 '20 04:10 archie94

Any updates?

QuinnMcCarthy avatar Nov 04 '20 16:11 QuinnMcCarthy

We are having the same warning message when switching the Mainactivity to the foreground. Waiting for updates. Thanks.

jasonhaihuang avatar Nov 06 '20 05:11 jasonhaihuang