Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@roeierez
Copy link
Contributor

@roeierez roeierez commented May 6, 2019

Background:

On Android there is a different behavior than in iOS which I think is the expected one.

  1. When clicking on a link while the app is running and then trying to get the link via a call to "retrieveDynamicLink" the result is null.
  2. Calling to "retrieveDynamicLink" doesn't clean the old value which makes it impossible for the application to know if/when the user has clicked a link or it is a result of an old click.

To solve the first problem I added a check for the existence of a dynamic link on every new intent instead of the current behavior that checks only on the fluter activity intent.

In addition (for the second problem) I added a cleanup for the old link every time it was retrieved
successfully by the user.

This PR matches the behavior on iOS.

Breaking Change

The retrieveDynamicLinks will now clean the value that it returns, means it will return a specific link only once.

@bparrishMines
Copy link
Contributor

Hi @roeierez,

Thanks for the contribution!

You said that you were unable to retrieve the link while the app was already running. The plugin should already be able to handle this. Where did you click a link that led to retrieveDynamicLink to be null? It may fail in a specific case. Using registrar.activity().getIntent() should suffice as the FlutterActivity is the only activity in a full Flutter app.

Also, according to the documentation, the call to getDynamicLink() already clears the data on first call. We modeled the iOS side to behave what the Android side should do automatically.

@roeierez
Copy link
Contributor Author

roeierez commented May 7, 2019

Hi @bparrishMines,

Thanks for your quick reply!

You said that you were unable to retrieve the link while the app was already running. The plugin should already be able to handle this. Where did you click a link that led to retrieveDynamicLink to be null? It may fail in a specific case. Using registrar.activity().getIntent() should suffice as the FlutterActivity is the only activity in a full Flutter app.

Hi, sorry for not being clear. The case is exactly as follows:

  1. open the app.
  2. click the link.
  3. on resuming, call to retrieveDynamicLink. - the result is null.

I think the problem resides in the fact that the code always use registrar.activity().getIntent() which is the intent that started the flutter activity and not the one that was created when the user clicks the link.
flutter activity is configured as singleTop android:launchMode="singleTop" and according to android documentation (https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)) in these cases the onNewIntent should be called for the new click intent. I am using "singleTask" but I don't think it matters for this discussion.
In the PR I am checking this intent via the onNewIntent listener which contains the link data.

Also, according to the documentation, the call to getDynamicLink() already clears the data on first call

Yes I see that although from my experience (I tested again) after I start the app with a link every call to "retrieveDynamicLink" returns the same link without cleaning it.

@kroikie kroikie changed the title firebase_dynamic_links: support clicking on link while app is running. [firebase_dynamic_links] support clicking on link while app is running. May 13, 2019
@Baileypollard
Copy link

I’m having this exact issue on IOS. Android is working fine for me. Could this be a problem with our fire base configuration?

… running.

This commit checks for dynamic links on any new intent and remove the
limitation for the fluter activity intent only.
This way users can retrieve the dynamic link that was clicked while the app
was running.
In addition the old links is cleaned up every time the link was sent
successfully to the user to get a better and more expected behavior.
This behavior now matches the behavior on ios.
@bparrishMines
Copy link
Contributor

Hi @roeierez,

I was unable to reproduce the bug for the first problem. Based on your explanation and the documentation for onNewIntent, you should be correct. If this PR solves this problem for you, then we can go ahead and submit.

I was able to reproduce the second bug and changed your code a little to cache the intent rather than storing the task and data.

@bparrishMines
Copy link
Contributor

@Baileypollard which problem are you running into on iOS?

  1. When clicking on a link while the app is running and then trying to get the link via a call to "retrieveDynamicLink" the result is null.
  2. Calling to "retrieveDynamicLink" doesn't clean the old value which makes it impossible for the application to know if/when the user has clicked a link or it is a result of an old click.

Would you mind creating a separate issue for iOS? If not, I can create it.

@roeierez
Copy link
Contributor Author

@bparrishMines thanks. Caching the intent looks good to me.

@bparrishMines bparrishMines merged commit bc04a77 into flutter:master May 29, 2019
Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DharmaTech123
Copy link

Still facing the same issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants