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

Branch listener invoking again after coming on foreground

Open aadityapaliwal opened this issue 1 year ago • 2 comments

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
}

aadityapaliwal avatar Jun 28 '24 08:06 aadityapaliwal

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.

github-actions[bot] avatar Aug 29 '24 00:08 github-actions[bot]

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

aadityapaliwal avatar Aug 30 '24 11:08 aadityapaliwal

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.

github-actions[bot] avatar Nov 09 '24 00:11 github-actions[bot]

This issue has been closed due to inactivity. If this issue is still relevant, please reopen it or create a new one. Thank you for your contributions.

github-actions[bot] avatar Nov 16 '24 00:11 github-actions[bot]