Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
java.lang.IllegalStateException: no puede acceder a ViewModels de NavBackStackEntry hasta que se agregue a la pila trasera de NavController

He creado un composable llamado ResolveAuth. ResolveAuth es la primera pantalla cuando el usuario abre la aplicación después de Splash. Todo lo que hace es verificar si un correo electrónico está presente en Datastore o no. En caso afirmativo, redirija a la pantalla principal y, en caso contrario, redirija a la pantalla del tutorial.

Aquí está mi código composable y viewmodel de vista

 @Composable fun ResolveAuth(resolveAuthViewModel: ResolveAuthViewModel, navController: NavController) { Scaffold(content = { ProgressBar() when { resolveAuthViewModel.userEmail.value != "" -> { navController.navigate(Screen.Main.route) { popUpTo(0) } resolveAuthViewModel.userEmail.value = null } resolveAuthViewModel.userEmail.value == "" -> { navController.navigate(Screen.Tutorial.route) { popUpTo(0) } resolveAuthViewModel.userEmail.value = null } } }) } @HiltViewModel class ResolveAuthViewModel @Inject constructor( private val dataStoreManager: DataStoreManager): ViewModel(){ val userEmail = MutableLiveData<String>() init { viewModelScope.launch{ val job = async {dataStoreManager.email.first()} val email = job.await() if(email != ""){ userEmail.value = email } } } }

Pero sigo recibiendo una excepción diciendo

 java.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels until it is added to the NavController's back stack (ie, the Lifecycle of the NavBackStackEntry reaches the CREATED state).

Estoy usando debajo de jetpack lib para navegar

 implementation("androidx.navigation:navigation-compose:2.4.0-rc01")

No hay ningún problema en mi pantalla principal y tutorial, ya que intenté ejecutarlos por separado y funciona bien.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!