android-branch-deep-linking-attribution
android-branch-deep-linking-attribution copied to clipboard
Branch listener invoking again after coming on foreground
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
- Tap on the branch link.
- It will open the app and invoke the branch listener with data
- Complete the task.
- 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
}