Delay using coroutine, splash activity delay, kotlin global scope

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

    super.onViewCreated(view, savedInstanceState)
(activity as MainActivity).hideBottomNavigationView()

lifecycleScope.launch {
delay(1000)
//check if user is already logged in

if (FirebaseAuth.getInstance().currentUser != null) {
try {
view.findNavController().navigate(R.id.action_fragment_splash_screen_to_homeFragment)
} catch (e : Exception){
e.printStackTrace()
}
} else {
if (findNavController().currentDestination?.id == R.id.fragment_splash_screen) {
try{
view.findNavController().navigate(R.id.splash_screen_to_login_fragment)
}catch (e :Exception){
e.printStackTrace()
}
}
}
}

Comments

Popular posts from this blog

Raw method for HTTP request containing all basic operations and under the hood methods and Classes: