8

When I open my application from the link if it is on stack already (opened) nothing happens. The existing instance of the app is opened, without any redirections. I found that the reason for this one intent is called. So, I added setIntent(newIntent) inside onNewIntent method, but it did not help. Then I added the following code:

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        //did not help
        //setIntent(intent)
        findNavController(R.id.container).handleDeepLink(intent)
    }

But, then onNewIntent is called twice. The log result after the click on the link is: (when there exists the app instance)

2019-11-19 10:43:18.758 D/CORN_DEBUG: onNewIntent
2019-11-19 10:43:18.805 D/CORN_DEBUG: onNewIntent
2019-11-19 10:43:19.248 D/CORN_DEBUG: onCreate Main Activity

Otherwise, the result is:

2019-11-19 10:45:05.272 D/CORN_DEBUG: onCreate Main Activity
2019-11-19 10:45:05.524 D/CORN_DEBUG: onNewIntent
2019-11-19 10:45:06.041 D/CORN_DEBUG: onCreate Main Activity

As onCreate is called twice, the screen flickers. What is the problem?

P.S. launch mode is single task.

MurugananthamS
  • 2,395
  • 4
  • 20
  • 49

1 Answers1

0

Handling deep links It is strongly recommended to always use the default launchMode of standard when using Navigation. When using standard launch mode, Navigation automatically handles deep links by calling handleDeepLink() to process any explicit or implicit deep links within the Intent. However, this does not happen automatically if the Activity is re-used when using an alternate launchMode such as singleTop. In this case, it is necessary to manually call handleDeepLink() in onNewIntent(), as shown in the following example:

https://developer.android.com/guide/navigation/navigation-deep-link#handle

jnr
  • 229
  • 2
  • 5