This issue has been addressed in similar posts, however, my situation is a little different. I have only ONE activity, and multiple fragments. I am not deeplinking into specific fragments, I am launching my one activity and then redirecting to the different fragments. The issue I am running into is that multiple instances of the app is opening when clicking on the deep link and when preventing multiple instances of the app from opening I lose the data in my intent for deep linking.
I have prevented multiple instances a couple of ways. One was was by adding singleTop to my manifest
android:launchMode="singleTop"
This prevents multiple instances, however, the static data from my original app instance gets lost. Another way I have also tried the below way as well
// finishes activity if its not the root activity
if (!FrameworkUtils.checkIfNull(getIntent().getExtras())) {
if (!isTaskRoot()) {
finish();
}
}
With this code, I maintain the original instance of the app, but the intent data I need from the deep link is gone because the new instance of the app (which I need) gets closed.
How can I resolve this situation without having to create additional Activities to launch and then doing something like
Intent intent = getIntent();
String intentUrl = intent.getDataString();
Intent newIntent = new Intent(this, MainActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra("intentUrl",intentUrl);
newIntent.setAction(Long.toString(System.currentTimeMillis()));
startActivity(newIntent);
finish();
Or rather, how can I remove the original instance of the app and keep the new instance of the app after the user clicks on the deep link? Thanks in advance