'android navigation component: Show view above current showing fragment when app come from background

I working on android app with navigation component, I want to show a pass-code view when app return from background, I don't know the best way to achieve that, but I create a BottomSheetDialogFragment I tried to call it from activity onRestart method but it dose not work so I write my code on onStart method but it still not working, my code bellow:

override fun onStart() {
    super.onStart()

    val  navHostFragment =
        (supportFragmentManager.findFragmentById(R.id.fragment_host) as NavHostFragment)
    val inflater = navHostFragment.navController.navInflater
    navGraph = inflater.inflate(R.navigation.navigation)
    val sharedPref = this.applicationContext?.let { SharedPrefImpl(it) }
    if (sharedPref != null) {
        if (sharedPref.ifKeyExist(PIN_CODE)) {
            navGraph.startDestination = R.id.homeFragment
            findNavController(R.id.fragment_host).navigate(R.id.pinFragment)
        } else {
            navGraph.startDestination = R.id.loginFragment
            navHostFragment.navController.navigate(R.id.loginFragment)
        }

    } else {
        findNavController(R.id.fragment_host).navigate(R.id.loginFragment)
    }
    navHostFragment.navController.graph = navGraph
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source