joghm
joghm

Reputation: 707

Navigation component navigate inside a onActivityResult not working

i am using
navController.navigate(R.id.FragmentB) to navigate from host fragment in MainActivity to navigate to different fragments and it works like expected except inside onActivityResult it won't respond ,i am returning an ID from other activity and want to navigate to Fragments depending on that ID but it is not responding ,

Upvotes: 5

Views: 841

Answers (2)

Simon
Simon

Reputation: 2733

If you're not using coroutines, a simple Handler() will do the trick.

Handler().post {
    navigate()
}

Upvotes: 4

joghm
joghm

Reputation: 707

It turns out that i needed to create a Coroutine and run my navigation function on it , i tried with :

  GlobalScope.launch(Dispatchers.Main) {
    navigate()
    }

and it works fine, obviously gotta need to optimise my coroutine ,but that was the main issue

Upvotes: 2

Related Questions