From d9fd534664d685a6f5b1df9563fb40c3b8ea0c92 Mon Sep 17 00:00:00 2001 From: Jonathan Nobels Date: Wed, 10 Apr 2024 11:09:36 -0400 Subject: [PATCH] android/ui: prevent navigation before we've added content 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 --- android/src/main/java/com/tailscale/ipn/MainActivity.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/tailscale/ipn/MainActivity.kt b/android/src/main/java/com/tailscale/ipn/MainActivity.kt index 2b9fbb5..f5900bc 100644 --- a/android/src/main/java/com/tailscale/ipn/MainActivity.kt +++ b/android/src/main/java/com/tailscale/ipn/MainActivity.kt @@ -74,11 +74,10 @@ import kotlinx.coroutines.launch class MainActivity : ComponentActivity() { private lateinit var requestVpnPermission: ActivityResultLauncher - 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) } }