Answer the question
In order to leave comments, you need to log in
How to deal with not associated with a fragment manager?
Crashlitics regularly receives an error like
Fatal Exception: java.lang.IllegalStateExceptionFragment SplashFragment{fc97135} (45cab3da-afe1-4c68-ac84-49080333cf2c)} not associated with a fragment manager.
Initially arrived at the sink with findNavController()
Handler().postDelayed({
findNavController().navigate(R.id.action_splashFragment_to_startFragment)
}, 2000L)
GlobalScope.launch {
delay(2000L)
withContext(Dispatchers.Main) {
val navBuilder = NavOptions.Builder()
val navOptions: NavOptions =
navBuilder.setPopUpTo(R.id.splashFragment, true).setLaunchSingleTop(true).build()
findNavController().navigate(R.id.startFragment, null, navOptions)
}
}
Answer the question
In order to leave comments, you need to log in
You should not use GlobalScope on Android at all.
Most likely, the timer fires at the moment when the fragment (or activity) has already been killed. It is necessary to take into account its life cycle.
Ideally, move this code to the presenter (ViewModel) and kill the job along with the death of this presenter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question