android-branch-deep-linking-attribution
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
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"
@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.
I am facing the same issue, please help.
same here Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true
People who are still facing issue can try to change the gradle version to: 4.3.1. It worked for me, might help you.
When you init in App: Application() you can do this: Branch.getAutoInstance(applicationContext) // not baseContex
@pnkshir @alim2020 @dmitrig01 @fcopello @Piyush2769
Any updates about this issue?
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
Any update?
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.
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);
}
Any news on this issue? Facing the same issue here.
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.
Facing same issue in our production app. Please provide with resolution.
Any updates?
I was able to fix this issue by moving the initialization of branch io from onCreate/onResume to onStart
any updates?
updates please
Same issue, any updates?
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?
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.
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?
Facing the same issue with 5.0.15 version as well.
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)
Any progress on this? 1.5 years now...
How do I deal with this issue in managed expo app? I do not have access to the android intent.
I'm dealing with the same issue
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.