Description
Environment:
Android device: OnePlus 5 A5000
Android OS Version: 8.1 (27)
Google Play Services version: 11.8.0
Firebase/Play Services SDK version: 11.8.0
According by Dynamic Links docs:
You must call getDynamicLink() in every activity that might be launched by the link, even though the link might be available from the intent using getIntent().getData(). Calling getDynamicLink() retrieves the link and clears that data so it is only processed once by your app.
For compatibility issues for devices which not supporting App Links, I'm loading Dynamic Links on main activity and routing to desired activity according Uri. So what I did:
@Override
public void onStart() {
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, pendingDynamicLinkData -> {
if (pendingDynamicLinkData != null) {
if (BuildConfig.VERSION_CODE >= pendingDynamicLinkData.getMinimumAppVersion()) {
routeDeepLinkIntent(this, pendingDynamicLinkData.getLink());
} else {
Intent update = pendingDynamicLinkData.getUpdateAppIntent(this);
startActivity(update);
}
}
})
.addOnFailureListener(this, e -> Log.w("DynLink", "On Failure", e));
}
In routeDeepLinkIntent(activity, uri) (very simplified)
if (uri.getPath().equals("activityToOpen") {
Intent intent = new Intent(activity, ActivityToOpen.class);
activity.startActivity(intent);
}
And works flawlessly, but, if I go back to previous activity, .getDynamicLink(getIntent()) will return dynamic link again and the process will repeat some times until stops. So the behavior is different from documentation.
If I put the code in onCreate(), dynamic link will works, but, if app is already opened, dynamic link will not work. Ok, because I ran .getDynamicLink(getIntent()) on onCreate, so activity is already created and getDynamicLink() will not be called.
How can I fix this, if possible?