Nav component don't navigate from blocking screen's notification

94 views Asked by At

I am receiving notification from firebase, it navigates correctly if receive it on foreground or background. But if I tap on notification from blocking screen it does not work. I think the problem is from not finding navController. But don't know what to do

 class MainActivity : AppCompatActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
    setTheme(R.style.MainTheme)
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main2)
    mainviewModel.navigateToMainFragmentEvent.observe(this, EventObserver {
      Log.d("A","notification")`
            Navigation.findNavController(this, R.id.nav_host_fragment)
                .navigate(R.id.action_global_mainFragment)
    })
  }
}

SplashFragment is a homeFragment

class SplashFragment : Fragment(R.layout.activity_splash) {
val splashViewModel: SplashViewModel by sharedViewModel()
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
      getStringExtra(NOTIFICATION_TYPE)?.let {
        splashViewModel.notificationRecived(it)
      }
  }
}

when I debug this code:

  Navigation.findNavController(this, R.id.nav_host_fragment)

IllegalStateException: ID does not reference a View inside this Activity

0

There are 0 answers