I have a problem with navigation. It is working perfectly on my Wear OS emulator but crashing on my ...
n
I have a problem with navigation. It is working perfectly on my Wear OS emulator but crashing on my Pixel watch. I would love it if someone could please help! 😊 Details in thread.
Here is the Navigation Composable:
Copy code
@Composable
fun Navigation() {
    val navController = rememberNavController()

    NavHost(navController = navController, startDestination = Screen.MainScreen.route) {
        composable(route = Screen.MainScreen.route) {
            MainApp(navController = navController)
        }
        composable(
            route = Screen.DescriptionScreen.route + "/{description}/{pubDate}",
            arguments = listOf(
                navArgument("description") {
                    type = NavType.StringType
                    defaultValue = ""
                    nullable = true
                },
                navArgument("pubDate") {
                    type = NavType.StringType
                    defaultValue = ""
                    nullable = true
                }
            )
        ) { entry ->
            DescriptionScreen(
                entry.arguments?.getString("description"),
                entry.arguments?.getString("pubDate"),
                navController
            )
        }
    }
}
Here is the rest of the code:
Copy code
sealed class Screen (val route: String){
    object MainScreen: Screen("main_screen")
    object DescriptionScreen: Screen("description_screen")

    fun withArgs(vararg  args: String): String{
        return buildString {
            append(route)
            args.forEach {arg ->
                append("/$arg")
            }
        }
    }
}
And the error looks like this:
Navigation destination that matches request NavDeepLinkRequest{ uri=<android-app://androidx.navigation/description_screen/><p>Exclusive: Dave Lewis, chair of the startup hoping to provide 8% of Britain's energy, talks about net zero frustrations</p><p>An £18bn project to connect Britain with a huge wind and solar farm in the Sahara through an undersea cable has been delayed by at least a year because of political ructions in Westminster.</p><p>The energy startup Xlinks hopes to provide 8% of Britain's energy supplies through a 3,800km (2,360-mile) cable linking Morocco with the UK, powering 7m homes by 2030.</p> <a href="<https://www.theguardian.com/business/2022/dec/04/government-chaos-delays-uk-sahara-energy-link>">Continue reading...</a>/Sun, 04 Dec 2022 16:31:29 GMT } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x26775c05) route=main_screen}
y
That description doesn't look ideal for a navigation argument. Especially in the path. With / in the text.
Why not pass the id and look that up instead?
Also you aren't using wear compose navigation here, but I don't think that's the issue
n
Oh
Hmm there is no id in the page I am drawing the info from. It's called "description". https://www.theguardian.com/uk/rss
I am getting the title fine. And the description works for the emulator. Strange...
y
It's failing to find a uri that seems to include <p>...
n
message has been deleted
y
And a newline and /. I guess you can encode it, but seems awkward to manage that cleanly
n
They all have <p> in them
y
Does it work if you replace the description with something fake and safe, like "xxxxx"
n
I'll try
y
I meant here, since this doesn't look like it handles string arguments that have URI reserved characters in it, like '/' or '?'
Copy code
fun withArgs(vararg  args: String): String{
        return buildString {
            append(route)
            args.forEach {arg ->
                append("/$arg")
            }
        }
    }
n
I'm getting this:
Navigation destination that matches request NavDeepLinkRequest{ uri=<android-app://androidx.navigation/description_screenxxxxxx> } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x26775c05) route=main_screen}
y
I assume you need a / there
n
uh
Yes it works
But it sounds like a bad idea to be sending variable length content with problematic characters in the navigation path. Try to avoid if you can help it.
n
Would it be better to make the call again in the description screen? I debated it and decided that it would be more efficient to pass the String.
y
Where are you loading from? DB, or remote API?
n
it's an rss feed reader, so the internet
y
I wouldn't hit the internet again.
n
I'm using Ktor
y
If you know it's cached, maybe not too bad. Or cache your self in the repository for this case.
Or just encode it safely first.
n
ok great, many thanks!
2970 Views