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

setNetworkTimeout not working as expected #878

Open Mathbl opened 3 years ago

Mathbl commented 3 years ago

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.

markchristopherng commented 3 years ago

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

markchristopherng commented 3 years ago

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

jf-branch commented 2 years ago

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.