I know that we can get the url that opened that app using Linking.getInitialUrl()
and also use
Linking.addEventListener('url', handler)
to get it when the app is in the background state.
Unfortunately, there's no way to get the latest deep link url visited when the app is opened while it was in the background state (minimized or another app was opened) long enough that it's memory is freed up either by manually freeing the memory using built-in tools (e.g. memory cleaner) or it was freed up by the system.
Scenario:
- App is opened using a deep link url.
- Open another app and wait for the OS to free up the memory of the previously opened app.
- Re-open the app using another deep link url.
- There's no way to get the latest deep link url, since
Linking.getInitial()
returns the first deep link url that opened it, whileLinking.addEventListener
will unfortunately not get the latest url since the entire app has been re-mounted.
Question: Is there a way to get the latest deep link url from the scenario above?
EDIT:
I solved this issue by using one of the solutions posted in this question:
Here's the relevant code:
In your MainActivity class, in android/app/src/main/java/com/{your-project}/MainActivity.java.
Import the relevant package for Intent
:
import android.content.Intent;
Add the method below:
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}