-1

I can't move automatically one activity to another activity in few seconds in KOTLIN (android studio) . Can you answer it how can I move like this

Automaticallt move in kotlin android studio

1 Answers1

0

https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescope

        lifeCyclerScope.launch {
        viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
            launch {
                delay(5000) //milisec
            //after 5 sec delay do it !

            } 
        }

And if you dont need an activity, work with fragment and use fragment navigation

https://developer.android.com/guide/navigation/navigation-getting-started

lifescyclerscope and navigation example

    class MyFragment: Fragment {
    init { // Notice that we can safely launch in the constructor of the Fragment.
        lifecycleScope.launch {
            whenStarted {
                // The block inside will run only when Lifecycle is at least STARTED.
                // It will start executing when fragment is started and
                // can call other suspend methods.
                loadingView.visibility = View.VISIBLE
                val canAccess = withContext(Dispatchers.IO) {
                    checkUserAccess()
                }

                // When checkUserAccess returns, the next line is automatically
                // suspended if the Lifecycle is not *at least* STARTED.
                // We could safely run fragment transactions because we know the
                // code won't run unless the lifecycle is at least STARTED.
                loadingView.visibility = View.GONE
                if (canAccess == false) {
                    findNavController().popBackStack()
                } else {
                    showContent()
                }
            }

            // This line runs only after the whenStarted block above has completed.

        }
    }
   }
Crebain
  • 180
  • 1
  • 8