implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
import androidx.navigation.fragment.NavHostFragment;
...
NavHostFragment.findNavController(fragment).navigate(R.id.destination);
kotlin
plugins {
id 'androidx.navigation.safeargs'
}
dependencies {
def nav_version = "2.3.5"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
// Other dependencies
}
String name = DestinationFragmentArgs.fromBundle(getArguments()).getName();
int age = DestinationFragmentArgs.fromBundle(getArguments()).getAge();
Bundle bundle = new Bundle();
bundle.putString("name", "John");
bundle.putInt("age", 25);
NavHostFragment.findNavController(fragment).navigate(R.id.destination, bundle);