android/ui: prevent navigation before we've added content (#306)

Fixes tailscale/corp#19070

If the activity hadn't yet been created, we can still get an onIntent which
was assuming the navController had been instantiated.  Switched that to
and optional so that we can null check it.

Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
pull/301/head
Jonathan Nobels 3 weeks ago committed by GitHub
parent a325a90558
commit cc244812a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -74,11 +74,10 @@ import kotlinx.coroutines.launch
class MainActivity : ComponentActivity() {
private lateinit var requestVpnPermission: ActivityResultLauncher<Unit>
private lateinit var navController: NavHostController
private var navController: NavHostController? = null
companion object {
private const val TAG = "Main Activity"
private const val START_AT_ROOT = "startAtRoot"
}
@ -245,7 +244,7 @@ class MainActivity : ComponentActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
if (intent?.getBooleanExtra(START_AT_ROOT, false) == true) {
navController.popBackStack(route = "main", inclusive = false)
navController?.popBackStack(route = "main", inclusive = false)
}
}

Loading…
Cancel
Save