android-branch-deep-linking-attribution
android-branch-deep-linking-attribution copied to clipboard
setNetworkTimeout not working as expected
I'm currently integrating Branch into a SplashActivity. Here's the code :
class SplashActivity: AppCompatActivity() {
private val branchListener = Branch.BranchReferralInitListener { referringParams: JSONObject?, error: BranchError? ->
if (error == null) {
referringParams?.let { params ->
if (params.has("code")) {
handleBranchCode(code)
} else {
routeToAppropriatePage()
}
} ?: kotlin.run {
routeToAppropriatePage()
}
} else {
Timber.e(error.message)
routeToAppropriatePage()
}
}
override fun onStart() {
super.onStart()
Branch.sessionBuilder(this).withCallback(branchListener).withData(this.intent?.data).init()
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
this.intent = intent
Branch.sessionBuilder(this).withCallback(branchListener).reInit()
}
}
I did some testing and simulated a case where the network is very slow or completely unavailable. The expected behavior is that branch will timeout after 5 seconds (Branch.getAutoInstance(this).setNetworkTimeout(5000)
), but it often takes more than 20 seconds (up to 35 seconds sometimes) for the listener to be fired.
I was already reluctant to base all my routing code on the fact that branch fires its callback correctly, but i'm now convinced this is not a good idea.
After digging through the issues, I found this https://github.com/BranchMetrics/android-branch-deep-linking-attribution/issues/605, but it is outdated and doesn't provide an official solution. If you are aware that setNetworkTimeout
isn't reliable, can you provide an official implementation of handling this?
I want branch to try to init, but if it takes more than 5 seconds and the callback hasn't fired yet, I want to just proceed with my usual routing. I don't want the user to be stuck on my SplashActivity for 30 seconds.
Thanks.
Having the same issue where on a poor internet connection Branch can take up to 30 seconds to initialise, lots of customers are complaining about app slow to load
you can use the following solution to set a timeout for the overall init() https://github.com/BranchMetrics/android-branch-deep-linking-attribution/issues/880#issuecomment-739669517
Hello and thank you for this feedback. The team is currently evaluating how we can improve upon our threading and queues to provide a more efficient and friendly SDK.