I have the SingleActivity
app developed with Jetpack Compose
and compose navigation
.
I need to handle deep links with query parameters.
At the moment my implementation includes the definition of deep links in the NavHost
and this is all.
But I have few issues with this approach:
How can I solve these issues?
I solved it by changing launchMode
of the MainActivity
to singleTask
. Previously it was a default standard
mode:
android:launchMode="singleTask"
And adding handling deep link by NavHostController
in the setContent
function inside the onCreate
method of MainActivity
:
@AndroidEntryPoint
class MainActivity : FragmentActivity() {
private val viewModel: AppViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
actionBar?.hide()
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
val appState = rememberMyAppState()
// add this
DisposableEffect(Unit) {
val listener = Consumer<Intent> {
appState.value.navController.handleDeepLink(it)
}
addOnNewIntentListener(listener)
onDispose { removeOnNewIntentListener(listener) }
}
...
}
}
Also to fix blinking between splash and other app content I changed containerColor
and contentColor
of my main Scaffold