Firebase dynamic link is not opening my app as separate app in android

Viewed 1614

It is opening like thatWhy are firebase dynamic links not opening the separate app?

Here is the code which I'm using to creating the dynamic link

    Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()

            .setLink(Uri.parse(DEEP_LINK_URL))
            .setDynamicLinkDomain(domain)
            .setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
                    .setMinimumVersion(0)
                    .setFallbackUrl(marketUri)
                    .build())
            .buildShortDynamicLink()

            .addOnCompleteListener(activity, new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                    if (task.isSuccessful()) {
                        Uri shortLink = task.getResult().getShortLink();
                        Uri flowchartLink = task.getResult().getPreviewLink();
                        Log.d("DynamicLink", "shortLink: " + shortLink);
                        shareDeepLink(shortLink.toString());
                        Log.d("DynamicLink", "flowchartLink: " + flowchartLink);

                    } else {
                        // Error
                        // ...
                    }
                }
            });
2 Answers

WhatsApp is opening the Dynamic Link, and they are not opening it as a new task (FLAG_ACTIVITY_NEW_TASK).

Firebase Dynamic Links currently passes through most of the flags that the calling app used with the idea that if the calling app wanted to open the webpage in the same task stack, then the FDL app should do the same.

So in this case, there's no way to work around, sorry!

I know it's been a while since this question was asked but still: I've just tried to restart the MainActivity with the FLAG_ACTIVITY_NEW_TASK flag and it seems to be working fine!

Depending on your usecase, you might need to implement some way to transfer the information from the dynamic link to the "new" app instance.

fun checkForPendingLink(intent: Intent) {
    FirebaseDynamicLinks.getInstance()
            .getDynamicLink(intent)
            .addOnSuccessListener(activity) { pendingDynamicLinkData ->
  // Do something with the link's data

  //Since the app was opened via the link, it is on the back stack of the application containing the link
  //Restart the MainActivity as new task to decouple it
  val restartIntent = Intent(activity, MainActivity::class.java)
  restartIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
  startActivity(restartIntent)
  finish()
}
Related