Banch onInitFinished即使在超时后也没有被调用

时间:2017-03-17 08:25:57

标签: android branch.io

 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) {

当用户网速较慢时,有时不会调用我的onInitFinished。我已经看到该应用程序在尝试初始化分支

时停留超过30秒

1 个答案:

答案 0 :(得分:4)

来自分公司的Alex:

目前这是一个众所周知的边缘案例。我们正在修复,但是现在你可以实现如下的超时:

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();