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
399 stars 156 forks source link

Branch listener invoking again after coming on foreground #1208

Open aadityapaliwal opened 3 months ago

aadityapaliwal commented 3 months ago

Describe the bug

User comes on the app via Branch link and completes the process and go back to background. Now, as soon as user comes back on the app after, the branch listener gets called again with same parameters. I am also clearing the intent data after first invocation. Although, it's not happening everytime.

Steps to reproduce

f

  1. Tap on the branch link.
  2. It will open the app and invoke the branch listener with data
  3. Complete the task.
  4. Go to browser and come back on the app

Expected behavior

It shouldn't call the branch listener again with the same data.

SDK Version

5.12.0

Make and Model

Motorola Moto G73 5g,

OS

11, 14

Additional Information/Context

My MainActivity

override fun onStart() {
        super.onStart()
        AppLog.d("onStart", "called")
        Branch.sessionBuilder(this).withCallback(branchListener).withDelay(getWaitingTimeForIntent().toInt()).withData(this.intent.data).init()
    }
override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        AppLog.d("onNewIntent", "intent -> $intent")
        this.intent = intent
        handleIntent()
    }

private val branchListener = Branch.BranchUniversalReferralInitListener { branchUniversalObject, referringParams, error ->
        if (error == null) {
            branchUniversalObject?.contentMetadata?.convertToJson()?.let { jsonObject ->
                AppLog.e("BranchListener Invoke", "referringParams $jsonObject")
                mainViewModel.handleJsonData(jsonObject)
            }
        } else {
            AppLog.e("BRANCH SDK", error.message)
        }
    }

private fun handleIntent() {
        if (intent != null && intent.hasExtra("branch_force_new_session") && intent.getBooleanExtra("branch_force_new_session",false)) {
            AppLog.e("handleIntent", "Re init Branch")
            Branch.sessionBuilder(this).withDelay(getWaitingTimeForIntent().toInt()).withCallback(branchListener).reInit()
        }
    }

override fun onResume() {
        super.onResume()
        AppLog.d("onResume", "called")
        isActivityInitialized = true
        showAppContent()
    }

private fun getWaitingTimeForIntent() : Long {
    return if (isActivityInitialized) 1000 else 2000
}
github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale due to inactivity for 60 days. If this issue is still relevant, please respond with any updates or this issue will be closed in 7 days. If you believe this is a mistake, please comment to let us know. Thank you for your contributions.

aadityapaliwal commented 1 month ago

It is still happening for us in Production. Do we have any solution?