-1

I initialize the Branch instance as indicated by the Branch guide.

In my launcher activity, I have the following:

public void onStart() {
    super.onStart();

    Branch branch = Branch.getInstance();

    branch.initSession(new Branch.BranchReferralInitListener(){
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
            ...

It works fine when the user first opens the app. However, if the user backs out of the app, and then re-launches the app (so the app stays in memory; ie: the Application class onCreate is NOT called again), then things don't work as expected. The launcher activity is recreated and onStart is called, but the onInitFinished is never called again.

Any ideas on how to handle this situation?

Note: I'm using the latest branch release:

compile ('io.branch.sdk.android:library:2.+') {
    exclude module: 'answers-shim'
}
Wise Shepherd
  • 2,228
  • 4
  • 31
  • 43

1 Answers1

0

Because it is already inited. You are expecting a singleton (which means there is only one instance in an application scope) to be re-inited.

I have checked the source and followed the code, you can see the control in Branch at line 1196.

Good luck

MLavoie
  • 9,671
  • 41
  • 36
  • 56
Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30
  • Thx. Based on that code, the `onInitFinished` should be called even if the session is initialized. – Wise Shepherd Sep 26 '17 at 12:08
  • I thought its already being called once when you said it worked fine for the first time app launched. If its never called there should be credentials or configration issues. – Emre Aktürk Sep 26 '17 at 12:12
  • Do you call another function to init SDK? We may need to check documentation for implementation. – Emre Aktürk Sep 26 '17 at 12:13
  • 1
    If you have Branch configured correctly, your Activity mode should be `singleTask` i.e. there will be only one instance of the Activity at any given point in time. Hence, if you click on another Branch link with the App backgrounded or if you reopen the App by clicking the App icon, the `initSession` will not be called again. – Amruta Deshmukh Sep 26 '17 at 20:15