Skip to content

Android > Error: Session initialization already happened > No deeplink referringParams #50

@KirstenStake

Description

@KirstenStake

Problem

When sending a push notification (in this case via Braze) which hold a deep link on click, if the app in the background, it only opens the application but does not hold any of the referringParams data and shows an error of:

"Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true."

Screen Shot 2021-10-29 at 1 00 12 pm

If you leave the app to go back into background, then foreground it again, it suddenly has the branch data within the object and works as intended. It is on the first push click and app open (if the app has already been opened and is in the background) that it is empty and fails.

Platform

Android

Code

  • MainActivity.java
public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Additional plugins you've installed go here
    // Ex: registerPlugin(TotallyAwesomePlugin.class);
    registerPlugin(Contacts.class);
    registerPlugin(NativeBiometric.class);
    registerPlugin(BranchDeepLinks.class);
  }

  @Override
  protected void onNewIntent(Intent intent) {
    // super.onNewIntent(intent);
    // this.setIntent(intent);

    this.setIntent(intent);
    super.onNewIntent(intent);

    // handles warning:"session initialization already happened"
    if(intent != null) {
      intent.putExtra("branch_force_new_session", true);
    }
  }
}
  • CustomApplicationClass.java
public class CustomApplicationClass extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        // Branch logging for debugging
        Branch.enableLogging();
        
        if (SDK_INT >= 24) {
          UserManager um = getApplicationContext().getSystemService(UserManager.class);
          if (um == null || !um.isUserUnlocked()) return;
        }

        // Branch object initialization
        Branch.getAutoInstance(this);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Environment setup

  • Capcitor 3
  • Angular 12
  • "capacitor-branch-deep-links": "^4.0.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions