问题
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