diff --git a/library/src/main/kotlin/com/github/terrakok/cicerone/androidx/AppNavigator.kt b/library/src/main/kotlin/com/github/terrakok/cicerone/androidx/AppNavigator.kt index 9a5efe3..52b26d5 100644 --- a/library/src/main/kotlin/com/github/terrakok/cicerone/androidx/AppNavigator.kt +++ b/library/src/main/kotlin/com/github/terrakok/cicerone/androidx/AppNavigator.kt @@ -2,6 +2,8 @@ package com.github.terrakok.cicerone.androidx import android.content.ActivityNotFoundException import android.content.Intent +import android.os.Handler +import android.os.Looper import androidx.fragment.app.* import com.github.terrakok.cicerone.* import com.github.terrakok.cicerone.androidx.TransactionInfo.Type.ADD @@ -22,8 +24,15 @@ open class AppNavigator @JvmOverloads constructor( ) : Navigator { protected val localStackCopy = mutableListOf() + private val mainHandler = Handler(Looper.getMainLooper()) override fun applyCommands(commands: Array) { + mainHandler.post { + applyCommandsSync(commands) + } + } + + protected open fun applyCommandsSync(commands: Array) { fragmentManager.executePendingTransactions() //copy stack before apply commands diff --git a/sample/src/main/java/com/github/terrakok/cicerone/sample/ui/main/MainActivity.kt b/sample/src/main/java/com/github/terrakok/cicerone/sample/ui/main/MainActivity.kt index e7def6b..d7d7a3a 100644 --- a/sample/src/main/java/com/github/terrakok/cicerone/sample/ui/main/MainActivity.kt +++ b/sample/src/main/java/com/github/terrakok/cicerone/sample/ui/main/MainActivity.kt @@ -33,8 +33,8 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder { private val navigator: Navigator = object : AppNavigator(this, R.id.main_container) { - override fun applyCommands(commands: Array) { - super.applyCommands(commands) + override fun applyCommandsSync(commands: Array) { + super.applyCommandsSync(commands) supportFragmentManager.executePendingTransactions() printScreensScheme() }