I am using navigation component's type safe APIs to navigate. The app which I inherited uses several activities (2-3), and fragments everywhere else. One of the flows requires to navigate from a fragment of one activity to another activity. This works ok when I declare my graph destinations like so:

//Routes.kt @Serializable data class SecondScreen(val foo: Foo, val bar: String = "") //FirstActivity.kt findNavController().createGraph(SomeStartDestination) { activity<SecondScreen>( typeMap = mapOf( typeOf<Foo> to NavType.EnumType(Foo::class.java) ) ) { activityClass = SecondActivity::class } } //SecondActivity.kt fun onCreate() { val route = findNavController().currentBackStackEntry?.toRoute<SecondScreen>() print(route?.foo) // null print(route?.bar) // null }

The part that does not work is retrieving the args that were passed along. I suspect that when the SecondActivity gets created, its NavHost and NavController start out with an empty backstack. If I grab the intent extras, it seems to extract the data ok, yet I feel that it's more of a workaround than an idiomatic solution. I looked around but did not come across any documentation for such a scenario. Am I missing something?

Vas's user avatar

2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.