https://kotlinlang.org logo
#android
Title
# android
j

Jonny

07/09/2019, 6:05 PM
Hi everyone. I'm pretty much a beginner. Right now I'm moving from intents to using NavigationController. My issue is that when I'm adding arguments, there is no argument for Double.
google 2
j

Jean Paul Pacheco

07/09/2019, 6:08 PM
is using primitive wrappers an option when it comes to setting argument types in this case? I have not tried it personally but it might be an option.
j

Jonny

07/09/2019, 6:10 PM
I'm not sure what that means
Floot, Long, Boolean, String, Custom Parcelable, Custom Serializable
Are my alternatives
j

Jean Paul Pacheco

07/09/2019, 6:12 PM
I’m talking about something like
Copy code
<argument
    android:name="argDouble"
    app:argType="java.lang.Double" />
j

Jonny

07/09/2019, 6:16 PM
I'm trying it
Got an error about class is java.lang.Double but found Float
Copy code
Caused by: org.xmlpull.v1.XmlPullParserException: Type is java.lang.Double but found float: 0
        at androidx.navigation.NavInflater.checkNavType(NavInflater.java:262)
        at androidx.navigation.NavInflater.inflateArgument(NavInflater.java:226)
        at androidx.navigation.NavInflater.inflateArgumentForDestination(NavInflater.java:146)
is this the problem? android:defaultValue="0.0"
j

Jean Paul Pacheco

07/09/2019, 6:33 PM
ok after looking a bit more into it, it seems that it’s just not possible to work with doubles as things are. Possibly once it’s out of the beta or a coming update might support it, but even using the primitive wrappers doesn’t seem like it will work. What you could do maybe is pass the value you need in a bundle when calling
navigate()
j

Jonny

07/09/2019, 6:37 PM
hm. that's so odd that they aren't supporting Double
I need to pass google map location
j

Jean Paul Pacheco

07/09/2019, 6:39 PM
I’m sure its in the works, as I see more than a few people have brought this up in forums. Fingers crossed at least 🤞
j

Jonny

07/09/2019, 6:41 PM
Yes eventually 🙂.
How would you modify this code to make it work?
Copy code
val action = SetLocationFragmentDirections.actionDestinationSetLocationToDestinationFindJobs()
                action.lat = job.lat
                action.lon = job.lon
                findNavController().navigate(action)
It's hard learning android from scratch (almost). They keep the old functionality but you're not supposed to use it etc. A lot of talk when reading up on something is about how it's an improvement over the old technique that I don't yet know about.
I'm using a string instead, and then convert it back
I tried the bundle but the code gets messier and it doesn't use my action so it breaks my back stack