Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ,

like image 312
joghm Avatar asked Mar 11 '20 15:03

joghm


People also ask

Can we use navigation component for activities?

To take full advantage of the Navigation component, your app should use multiple fragments in a single activity. However, activities can still benefit from the Navigation component. Note, however, that your app's UI must be visually broken up across several navigation graphs.

What is the navigation component?

Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. The Navigation component also ensures a consistent and predictable user experience by adhering to an established set of principles.

What is NavController in Android?

NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.


1 Answers

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

Handler().post {
    navigate()
}
like image 145
Simon Avatar answered Sep 28 '22 07:09

Simon