https://kotlinlang.org logo
#compose
Title
# compose
d

Daniele B

02/17/2021, 2:42 PM
I have a master/detail app, using NavHost. I get a strange warning when I hit the back button from the Detail screen, and the screen goes back to Master:
D/InputDispatcher: Waiting to send key to Window{1bda786 u0 myapp.MainActivity} because there are unprocessed events that may cause focus to change
I am posting the code in a comment to this message. Am I setting up the NavHost incorrectly? Is this warning meaningful or should I disregard it? The app still works well.
This is the activity:
Copy code
class MainActivity : AppCompatActivity() {

  private val appViewModel: AppViewModel by viewModels()

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      MyAppTheme(appViewModel.KMPModel) {
        Navigation(appViewModel.KMPModel)
      }
    }
  }

}
This is the Navigation composable:
Copy code
@Composable
fun Navigation(model: KMPViewModel) {

  val appState by model.stateFlow.collectAsState()

  val navController = rememberNavController()

  NavHost(navController, startDestination = "master") {
    composable("master") {
      MasterView(model = model, masterState = appState.masterState) {
        navController.navigate("detail/$it")
        model.loadDetailItem(it)
      }
    }
    composable("detail/{item}") { backStackEntry ->
      val detailName = backStackEntry.arguments?.getString("item")!!
      DetailView(model = model, detailState = appState.detailState, detailName = detailName)
    }
  }

}
2 Views