BranchMetrics / android-branch-deep-linking-attribution

The Branch Android SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/pages/apps/android/
MIT License
397 stars 156 forks source link

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

Open Discovery-Prachi opened 4 years ago

Discovery-Prachi commented 4 years ago

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"

alim2020 commented 4 years ago

@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.

Piyush2769 commented 4 years ago

I am facing the same issue, please help.

fcopello commented 4 years ago

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

Piyush2769 commented 4 years ago

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

azatserzhan commented 4 years ago

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

@pnkshir @alim2020 @dmitrig01 @fcopello @Piyush2769

araujotadeu commented 3 years ago

Any updates about this issue?

StarryFire commented 3 years ago

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

PabloSanjuan1 commented 3 years ago

Any update?

archie94 commented 3 years ago

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.

bramski commented 3 years ago

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);
  }
PedroFabrino commented 3 years ago

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

sunnykraditya commented 3 years ago

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.

sudsingh438 commented 3 years ago

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

hsavit1 commented 3 years ago

Any updates?

kayschmitt commented 3 years ago

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

michtnt commented 3 years ago

any updates?

hsavit1 commented 3 years ago

updates please

rukmanary commented 2 years ago

Same issue, any updates?

rukmanary commented 2 years ago

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?

jf-branch commented 2 years ago

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.

Bej-Technologies commented 2 years ago

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?

ercanpinar commented 2 years ago

Facing the same issue with 5.0.15 version as well.

stephen-mojo commented 2 years ago

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)

Svarto commented 2 years ago

Any progress on this? 1.5 years now...

dmitryame commented 2 years ago

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

iganovir commented 2 years ago

I'm dealing with the same issue

dmitryame commented 2 years ago

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.

Binghaman commented 1 year ago

Not sure if this is right or not, as I am really new to Branch IO. But I was able to remove the error by adding the following line: this.intent?.putExtra("branch_force_new_session", true) This should work for me because this happens in my splash screen.

Svarto commented 1 year ago

Where did you put this?

Sent from Proton Mail mobile

-------- Original Message -------- On 25 Jan 2023, 20:52, Binghaman wrote:

Not sure if this is right or not, as I am really new to Branch IO. But I was able to remove the error by adding the following line: this.intent?.putExtra("branch_force_new_session", true) This should work for me because this happens in my splash screen.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Binghaman commented 1 year ago

Oh, sorry. I put it before this snippet:

Branch
    .sessionBuilder(this).withCallback { ... }
    .withData(this.intent.data)
    .init()
NicolasEymael commented 10 months ago

i solved the problem using @Binghaman solution is this going to be fixed or i need to use this "workaround" forever?

lukepighetti commented 8 months ago

Seeing this on Android with the Flutter SDK flutter_branch_sdk: 7.0.1

aadityapaliwal commented 5 months ago

I have started facing this issue suddenly in Android 33 and Android 34 devices and my app not redirecting the user on the desire page. Please check below logs -

InitSessionBuilder setting BranchReferralInitListener withCallback with 
InitSessionBuilder setting withData with xxxxx://open?_branch_referrer=H4sIAAAAAAAAA61S247TMBD9muZllNS5wDZIEeqFghCIVVf7jBx7kpj6tmNHu%2BXrcVpA%2B8gD1khzPWdsz0wx%2BvBuvZbkvC8ihpjzZGhlz2sxoThvvX%2Fv%2BWV32XF77iLNmMVpNr3lSnfTgl7V21V1TPLECz%2F3WoUJqbgRCpHiBqXiSTtSo7Jcf1eGjxhSJBXHn3nFms1LWb9luXGy%2BOHHzCCJidu4FcLNNnasYEXFWJtx89tvW8aymf71CsLZiDb%2BbSnRuNzP5F3A3Fl9SZlMzERoxaV7fDhkhAMuHnZ3Natx6O%2FyTf2mzJu2rJIl65zdNX1fN03ZtFUWVdTY7RZyWFWb9FY4pB7w7crdZvjiFWHoyoplEoMg5aNytqtYWUIOe1IG4UDccFh9qFYbtmprKOETQb2Br8q%2Bip5e2UelzUkFLD7z4Cw8RB4nbiBETgF4EohuHicQzsPz5P4A2wBSBc9jGrFMJRD5GUG6Z5sQAUlxDWelNdKCgikx9Yg2ldGIUdkRvNNKILhhSIpCAVsdHAzI40xL%2Fp5LeYG9s0FJZRG4lbBVMnF8XHhtcftg4vqI2JVpwOlkaUyDIvN4%2BvI%2F5%2FpEeyfxtrvXVd7vr84vKEH1efwCAAA%3D
Beginning session initialization
Session uri is xxxxx://open?_branch_referrer=H4sIAAAAAAAAA61S247TMBD9muZllNS5wDZIEeqFghCIVVf7jBx7kpj6tmNHu%2BXrcVpA%2B8gD1khzPWdsz0wx%2BvBuvZbkvC8ihpjzZGhlz2sxoThvvX%2Fv%2BWV32XF77iLNmMVpNr3lSnfTgl7V21V1TPLECz%2F3WoUJqbgRCpHiBqXiSTtSo7Jcf1eGjxhSJBXHn3nFms1LWb9luXGy%2BOHHzCCJidu4FcLNNnasYEXFWJtx89tvW8aymf71CsLZiDb%2BbSnRuNzP5F3A3Fl9SZlMzERoxaV7fDhkhAMuHnZ3Natx6O%2FyTf2mzJu2rJIl65zdNX1fN03ZtFUWVdTY7RZyWFWb9FY4pB7w7crdZvjiFWHoyoplEoMg5aNytqtYWUIOe1IG4UDccFh9qFYbtmprKOETQb2Br8q%2Bip5e2UelzUkFLD7z4Cw8RB4nbiBETgF4EohuHicQzsPz5P4A2wBSBc9jGrFMJRD5GUG6Z5sQAUlxDWelNdKCgikx9Yg2ldGIUdkRvNNKILhhSIpCAVsdHAzI40xL%2Fp5LeYG9s0FJZRG4lbBVMnF8XHhtcftg4vqI2JVpwOlkaUyDIvN4%2BvI%2F5%2FpEeyfxtrvXVd7vr84vKEH1efwCAAA%3D
Callback is com.opencrowd.drop.ui.MainActivity$$ExternalSyntheticLambda37@fd072e5
Is auto init false
Will ignore intent null
Is reinitializing false
Read params uri: xxxxx://open?_branch_referrer=H4sIAAAAAAAAA61S247TMBD9muZllNS5wDZIEeqFghCIVVf7jBx7kpj6tmNHu%2BXrcVpA%2B8gD1khzPWdsz0wx%2BvBuvZbkvC8ihpjzZGhlz2sxoThvvX%2Fv%2BWV32XF77iLNmMVpNr3lSnfTgl7V21V1TPLECz%2F3WoUJqbgRCpHiBqXiSTtSo7Jcf1eGjxhSJBXHn3nFms1LWb9luXGy%2BOHHzCCJidu4FcLNNnasYEXFWJtx89tvW8aymf71CsLZiDb%2BbSnRuNzP5F3A3Fl9SZlMzERoxaV7fDhkhAMuHnZ3Natx6O%2FyTf2mzJu2rJIl65zdNX1fN03ZtFUWVdTY7RZyWFWb9FY4pB7w7crdZvjiFWHoyoplEoMg5aNytqtYWUIOe1IG4UDccFh9qFYbtmprKOETQb2Br8q%2Bip5e2UelzUkFLD7z4Cw8RB4nbiBETgF4EohuHicQzsPz5P4A2wBSBc9jGrFMJRD5GUG6Z5sQAUlxDWelNdKCgikx9Yg2ldGIUdkRvNNKILhhSIpCAVsdHAzI40xL%2Fp5LeYG9s0FJZRG4lbBVMnF8XHhtcftg4vqI2JVpwOlkaUyDIvN4%2BvI%2F5%2FpEeyfxtrvXVd7vr84vKEH1efwCAAA%3D bypassCurrentActivityIntentState: false intent state: READY
extractExternalUriAndIntentExtras xxxxx://open?_branch_referrer=H4sIAAAAAAAAA61S247TMBD9muZllNS5wDZIEeqFghCIVVf7jBx7kpj6tmNHu%2BXrcVpA%2B8gD1khzPWdsz0wx%2BvBuvZbkvC8ihpjzZGhlz2sxoThvvX%2Fv%2BWV32XF77iLNmMVpNr3lSnfTgl7V21V1TPLECz%2F3WoUJqbgRCpHiBqXiSTtSo7Jcf1eGjxhSJBXHn3nFms1LWb9luXGy%2BOHHzCCJidu4FcLNNnasYEXFWJtx89tvW8aymf71CsLZiDb%2BbSnRuNzP5F3A3Fl9SZlMzERoxaV7fDhkhAMuHnZ3Natx6O%2FyTf2mzJu2rJIl65zdNX1fN03ZtFUWVdTY7RZyWFWb9FY4pB7w7crdZvjiFWHoyoplEoMg5aNytqtYWUIOe1IG4UDccFh9qFYbtmprKOETQb2Br8q%2Bip5e2UelzUkFLD7z4Cw8RB4nbiBETgF4EohuHicQzsPz5P4A2wBSBc9jGrFMJRD5GUG6Z5sQAUlxDWelNdKCgikx9Yg2ldGIUdkRvNNKILhhSIpCAVsdHAzI40xL%2Fp5LeYG9s0FJZRG4lbBVMnF8XHhtcftg4vqI2JVpwOlkaUyDIvN4%2BvI%2F5%2FpEeyfxtrvXVd7vr84vKEH1efwCAAA%3D com.opencrowd.drop.ui.MainActivity@c07a696
isIntentParamsAlreadyConsumed true
extractBranchLinkFromIntentExtra com.opencrowd.drop.ui.MainActivity@c07a696
isIntentParamsAlreadyConsumed true
isInstantDeepLinkPossible false
Creating io.branch.referral.ServerRequestRegisterOpen@14a6f64 from init on thread main
initializeSession io.branch.referral.ServerRequestRegisterOpen@14a6f64 delay 0
Warning: You are using your test app's Branch Key. Remember to change it to live Branch Key during deployment.
Intent: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=xxxxx://open/... flg=0x14400000 pkg=cc.xxxxx.wallet cmp=cc.xxxxx.wallet/com.opencrowd.drop.ui.MainActivity (has extras) } forceBranchSession: false initState: INITIALISED

Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.
PerezCodeT commented 2 months ago

Oh, sorry. I put it before this snippet:

Branch
    .sessionBuilder(this).withCallback { ... }
    .withData(this.intent.data)
    .init()

Hi @Binghaman What is the technology stack you are using for your Branch integration? I'm using react native with expo and I don't know where I can put that piece of code you suggest.

shuo-hiwintech commented 1 month ago

+1