1

I want to achieve the same result as this code, As I am using android navigation components what should I out in place of the fragment container as there is only NavHostFragment.

val newFragment = ExampleFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, newFragment)
transaction.addToBackStack(null)
transaction.commit()
curiousgeek
  • 903
  • 11
  • 18

1 Answers1

0

Assuming you have a destination in your navigation graph that looks like:

<fragment
  android:id="@+id/example"
  android:name=".ExampleFragment"/>

You'd simply call navController.navigate(R.id.example), getting a reference to your NavController via one of the methods described in the documentation.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • This method is not working in my case, I have explained my full situation in another question [link](https://stackoverflow.com/questions/53854226/android-jetpack-navigation-how-to-open-a-fragment-from-an-activity-not-associa) – curiousgeek Dec 19 '18 at 18:58