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

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

Open Discovery-Prachi opened this issue 5 years ago • 36 comments

We are getting following error :

io.branch.sdk.android:library: 4.3.2

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

We are using Firebase default Notification messages along with branch.io

Steps to reproduce:

If app is already open and then notification is received, then clicking on it navigates properly to desired deep link page.

But in following scenario it doesnt: Keep the app closed Send notification Open the app Click on notification Instead of deeplink, home page is opened Now exit the app and open again. This time the previous deeplink will be open.

Could you help us how to solve this issue .

Following is the code snippet in extended Application class : Branch.getAutoInstance(getContext())

In LaunchActivity :

public override fun onStart() { super.onStart() //Todo: Check this session initialisation intent?.putExtra(KEY_NEW_SESSION, true) Branch.getInstance().initSession( branchListener, intent?.data, this ) }

private val branchListener = Branch.BranchUniversalReferralInitListener { branchUniversalObject, linkProperties, error ->
    DeepLinkManager.getInstance()?.launchScreen(this, linkProperties, error, isFirstLaunch)
    isFirstLaunch = false
}

override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) this.intent = intent Branch.getInstance().reInitSession(this, branchListener) }

AndroidManifest.xml : Launch Activity is android:launchMode="singleTask"

Discovery-Prachi avatar Apr 29 '20 10:04 Discovery-Prachi

@dmitrig01 @chanian @funeric555 I am facing same issue with branch.io "Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.

alim2020 avatar Jun 21 '20 12:06 alim2020

I am facing the same issue, please help.

Piyush2769 avatar Jul 08 '20 10:07 Piyush2769

same here Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true

fcopello avatar Jul 13 '20 21:07 fcopello

People who are still facing issue can try to change the gradle version to: 4.3.1. It worked for me, might help you.

Piyush2769 avatar Jul 20 '20 11:07 Piyush2769

When you init in App: Application() you can do this: Branch.getAutoInstance(applicationContext) // not baseContex

@pnkshir @alim2020 @dmitrig01 @fcopello @Piyush2769

azatserzhan avatar Jul 28 '20 10:07 azatserzhan

Any updates about this issue?

araujotadeu avatar Sep 28 '20 13:09 araujotadeu

This is happening on android when i try to open the app's notification while the app is still in foreground. Its happening on the latest branch version v5.0

StarryFire avatar Sep 30 '20 06:09 StarryFire

Any update?

PabloSanjuan1 avatar Oct 01 '20 18:10 PabloSanjuan1

Hello! 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

When you init in App: Application() you can do this: Branch.getAutoInstance(applicationContext) // not baseContex

@pnkshir @alim2020 @dmitrig01 @fcopello @Piyush2769

Not sure how that works... the getAutoInstance call looks like this:

@Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
    RNBranchModule.getAutoInstance(this);
  }

bramski avatar Nov 19 '20 19:11 bramski

Any news on this issue? Facing the same issue here.

PedroFabrino avatar Dec 03 '20 21:12 PedroFabrino

Is this resolved? Joining the waiting gang. Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.

sunnykraditya avatar Feb 04 '21 16:02 sunnykraditya

Facing same issue in our production app. Please provide with resolution.

sudsingh438 avatar Feb 15 '21 12:02 sudsingh438

Any updates?

hsavit1 avatar Apr 12 '21 20:04 hsavit1

I was able to fix this issue by moving the initialization of branch io from onCreate/onResume to onStart

kayschmitt avatar Apr 22 '21 22:04 kayschmitt

any updates?

michtnt avatar May 06 '21 04:05 michtnt

updates please

hsavit1 avatar Sep 07 '21 17:09 hsavit1

Same issue, any updates?

rukmanary avatar Oct 11 '21 02:10 rukmanary

By the way, in my case, I use branch.openURL in push notification and this happens when the app is in the background. When I clicked push notification, I cannot navigate to designated screen as I expected.

And then I found this post https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/328#issue-305733874 and apply it. The Warning is still occur but the navigation is succeed.

But the author said he's not sure if that's how it is supposed to be done. So can anyone confirm this?

rukmanary avatar Oct 11 '21 03:10 rukmanary

Hello,

Thank you all for your feedback and input in raising this concern. I do want to call out that this is just a warning message and not an error message. Given the confusion, the team is evaluating proceeding with more clear and informative messaging to these "warnings".

With that said, to support Push notifications, please follow our instructions and add the additional boolean extra to the intent, "branch_force_new_session": true. Branch sessionBuilder initialization should also always occur within onStart() and not onCreate.

jf-branch avatar Oct 15 '21 19:10 jf-branch

I am getting this every time I open my Android app. Sure it's just a warning but it just creates lots of noise in our logs. We can ignore it but the solution I'd prefer is simply to fix the warning. From my understanding, it's caused because onStart is called every time you foreground the app and then it tries to initialize a session even though one is already active. Is it possible to check if a session is already active in onStart?

Bej-Technologies avatar Oct 19 '21 12:10 Bej-Technologies

Facing the same issue with 5.0.15 version as well.

ercanpinar avatar Nov 15 '21 01:11 ercanpinar

I was also seeing this message after handling a deep link. Here is what I think is going on in my case: If you use Jetpack Navigation to route your deep links like I do, the navigation framework re-creates the entire Activity before processing it. This can trigger onStart() again and thus another call to init(). Pretty sure this is what is causing me to see extra error messages about things already being initialized.

@Bej-Technologies I also don't think it is the case that "it's caused because onStart is called every time you foreground the app and then it tries to initialize a session even though one is already active" because if you look at the source, it handles that with a lifecycle listener by closing the session on stop. (See: https://github.com/BranchMetrics/android-branch-deep-linking-attribution/blob/9e68c86e7f8ecead27fa772b9ff60eb90a7a20be/Branch-SDK/src/main/java/io/branch/referral/BranchActivityLifecycleObserver.java#L105)

stephen-mojo avatar Nov 25 '21 02:11 stephen-mojo

Any progress on this? 1.5 years now...

Svarto avatar Nov 27 '21 17:11 Svarto

How do I deal with this issue in managed expo app? I do not have access to the android intent.

dmitryame avatar Dec 20 '21 16:12 dmitryame

I'm dealing with the same issue

iganovir avatar Jan 14 '22 12:01 iganovir

Looks like they are working on fixing branch for future https://github.com/expo/config-plugins/pull/28 But they are not very good at sharing estimates or providing guidelines https://forums.expo.dev/t/expo-branch-in-managed-app-does-not-work/60501/7 The best thing at this point is to keep waiting, hopefully the end to the branch issues in expo is near.

dmitryame avatar Jan 14 '22 14:01 dmitryame