Banch onInitFinished not called even after timeout

你离开我真会死。 提交于 2019-12-08 05:52:35

问题


 Branch branch = Branch.getInstance();
        branch.setRetryCount(1);
        branch.setRetryInterval(10);
        branch.initSession(new Branch.BranchUniversalReferralInitListener() {
            @Override
            public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError branchError) {

My onInitFinished is sometimes not called when the users net speed is slow. I have seen the app stuck more than 30 seconds on trying to initialize branch


回答1:


Alex from Branch here:

This is a known edge case at the moment. We're working on a fix, but for now you can implement a timeout like the following:

final CountDownLatch countDownLatch = new CountDownLatch(1);
    new Thread(new Runnable() {
        @Override
        public void run() {
            branch.initSession(new Branch.BranchUniversalReferralInitListener() {
                @Override
                public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) {
                    if(countDownLatch.getCount() > 0) {
                        countDownLatch.countDown();
                        postBranchInitSession(null);
                    }
                }
            });
            try {
                countDownLatch.await(5000, TimeUnit.MICROSECONDS);
            } catch (InterruptedException ignore) {
                postBranchInitSession(null);
            }
        }

    }).run();


来源:https://stackoverflow.com/questions/42852550/banch-oninitfinished-not-called-even-after-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!