Posts

Showing posts with the label splash

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 () } } } }

Handler and looper in splash

  if ( activity ?. intent ?. extras == null ) { Handler ( Looper . getMainLooper ()). postDelayed ( { //check if user is already logged in if ( FirebaseAuth . getInstance (). currentUser != null ) { try { findNavController (). navigate ( R . id . action_splashScreenFragment_to_inStoreTransactionsFragment ) } catch ( e : Exception ){ e . printStackTrace () } } else { try { view . findNavController (). navigate ( R . id . splash_screen_to_login_fragment ) } catch ( e : Exception ) { e . printStackTrace () } } } , 1000 ) }