2
 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

user2848975
  • 117
  • 1
  • 12

1 Answers1

4

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();
Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • Thanks for your reply. Is there anyway I can check when the user opens app whether he has been redircted to app from a branch link or he has opened app through other sources. If there is a check, then before Initializing branch I can check whether to intialise branch or not and then decide on the timeout – user2848975 Mar 20 '17 at 06:26
  • Unfortunately no...the only way to know this for sure is the `~clicked_branch_link` parameter that comes in the response from the initialization. These should be very rare in the wild, and hopefully we will have the proper fix or soon! – Alex Bauer Mar 20 '17 at 14:44
  • Hey, could you checkout the solution I posted? – user2848975 Mar 23 '17 at 06:11
  • Would you mind [submitting a ticket to our Integrations Team](https://support.branch.io/support/tickets/new) for this? We have a could Android experts who will be able to advise you better – Alex Bauer Mar 23 '17 at 06:47
  • Hey, the implementation you sugeested worked. Had to do little modifications just – user2848975 May 11 '17 at 06:11
  • Sorry for the silly question but can you please tell me what is `postBranchInitSession(null);` i am new to branch.io – Shaifali Rajput Sep 06 '17 at 06:09
  • @ShaifaliRajput that looks like a custom method in the OP's app. It's not part of the Branch SDK (at least, to my knowledge) – Alex Bauer Sep 06 '17 at 14:17
  • @AlexBauer Thank you :) – Shaifali Rajput Sep 07 '17 at 04:39