How to Pass Custom NavTypes in Compose Type-Safe Navigation - Android Studio Tutorial

Поділитися
Вставка
  • Опубліковано 6 січ 2025
  • In this video you'll learn how you can pass any type of data class as an argument from one screen to another using the new type-safe navigation framework.
    💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:
    pl-coding.com/...
    ⭐ Courses with real-life practices
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/...
    🎁 Get my FREE 4.5h course "The Best Practice Guide to Android Architecture":
    pl-coding.com/...
    Read our weekly Android blog:
    pl-coding.com/...
    Regular programming advice on my Instagram page: / _philipplackner_
    Join my Discord server:
    / discord
    Get the source code for this video on GitHub:
    github.com/phi...

КОМЕНТАРІ •

  • @Razo.TR0N
    @Razo.TR0N 4 місяці тому +12

    Yesterday was exactly two years of my sponsorship of your channel! Thank you Philipp for your videos and especially for the videos from Twitch, which two years ago opened the door to the world of development for me. Developing a full-fledged social network app on Compose with a multi-module clean architecture in combination with a KTOR backend and its deployment to the server is the best thing education material I have ever seen in my life.

  • @cfa532
    @cfa532 4 місяці тому

    The 2-weeks-old video is just in-time to solve my problem. Thanks a lot.

  • @NikNewNik
    @NikNewNik Місяць тому +2

    THANK YOU PHILIPP !!! It works !😃👍

  • @h4ktbtw
    @h4ktbtw 4 місяці тому +10

    Too bad they did not utilize the serialization fully. Registering custom NavTypes for serializable classess is such a bad design decision.

  • @АбдукаххорРахимов-ф9ц

    u are the best, thx for all of u videos

  • @sakibsyed7626
    @sakibsyed7626 Місяць тому

    Great and life saver ❤

  • @cristian1234584
    @cristian1234584 4 місяці тому +1

    Great! Philipp, do you have any video showing your Android Studio IDE configurations?

  • @renvzla
    @renvzla 4 місяці тому +3

    thanks for this video Philipp.
    Got a quick question. How could I extract the dog model from the savedStateHandle on the details screen viewmodel?

    • @ik024
      @ik024 3 місяці тому

      savedStateHandle.toRoute() ?

  • @ssSFrankSss
    @ssSFrankSss 17 днів тому

    So there is no need to use add sealed class NavigationScreens(val route: String) ?

  • @Tbijo54
    @Tbijo54 4 місяці тому

    Awesome video, thanks Philipp. Could you also make one explaining how to pass type safe arguments to a nested navigation?

    • @PhilippLackner
      @PhilippLackner  4 місяці тому

      @@Tbijo54 that's should be no different :)

    • @skyles146
      @skyles146 4 місяці тому

      The only thing you need to know for nested destination is that a startDestination can't have argument. That's all.

  • @Bandy_K7
    @Bandy_K7 4 місяці тому

    thanks for this video.
    if you can make a video on android auto and automotive os it would be great.

  • @raulprior9635
    @raulprior9635 4 місяці тому

    Hi Phillip can you show us how to build an interface for handle navigation actions with the navController in view models, but you know in a way that View Models still being testable, love you videos thanks so mucho

  • @leonelp9593
    @leonelp9593 3 місяці тому

    i know this is 1 month old...
    but is this still up to date witht the 2.8.1 compose navigation ? (the stable one) or is there an easiest way to do this?

  • @umidolimzhanov6078
    @umidolimzhanov6078 4 місяці тому

    Great video! Can I use it somehow to return result from screen?

  • @ndiritumichael
    @ndiritumichael 4 місяці тому +5

    the latest navigation release doesn't require the typeMap of enum to be passed.

    • @skyles146
      @skyles146 4 місяці тому +1

      It is required on beta07 on minified app or it will crash. There is an issue tracker on this and it will be solved in the next version 21st of August.

  • @flowzk921
    @flowzk921 4 місяці тому

    Awesome One!

  • @surjithkumar8177
    @surjithkumar8177 4 місяці тому

    Is this custom nav supports to add a screen transition?

  • @stevenrathmann7823
    @stevenrathmann7823 3 місяці тому

    Could you please explain how i can pass an argument from DogDetail back to DogList if the DogDetail Screen is finish?

  • @raghavaggarwal8644
    @raghavaggarwal8644 4 місяці тому +1

    Hi Philipp, you mentioned that one should not use this approach in case of big custom objects because the Bundle has some limits but I wonder why anyone has never highlighted the same before? Like people have been and still use Bundles for passing arguments to Fragments when they create a Fragment's instance. We are using the same Bundle class here too right?

    • @PhilippLackner
      @PhilippLackner  4 місяці тому +1

      This has been highlighted lots of times that it's better to pass an ID and reload something from the DB rather than passing the whole object. The official docs also suggest that somewhere

    • @raghavaggarwal8644
      @raghavaggarwal8644 4 місяці тому +1

      I see, need to read the docs about the Bundle limit. Thanks

  • @nott__aceu4857
    @nott__aceu4857 4 місяці тому

    I would rather save the data in a ViewModel than pass it as an argument (if its large data), What is your take on this ?

  • @kabindrashrestha3760
    @kabindrashrestha3760 3 місяці тому

    Hi @PhilippLackner , How to pass Custom NavTypes in Compose MultiPlatform for Type-Safe Navigation on Android and IOS?

  • @RABBITV
    @RABBITV 3 місяці тому

    Hi Philipp , rly thank you for this video , thx to you my routing start working . L have one question to you , why you in this code in NavType use Uri.decode and encode ? Why is is important to do it ? Again thx fro the video :)

    • @muhammadnaveeed9382
      @muhammadnaveeed9382 3 місяці тому +2

      If we don't use the URI then app will crash if we have some special characters like "?", "/" in params of Custom Type like for image of User can have these, so we need to encode & decode that to string.

  • @MattCM89
    @MattCM89 Місяць тому

    How do we do this for hilt-navigation? don't they conflict?

  • @MrPeanutMans
    @MrPeanutMans Місяць тому

    Is there a way to pass more complex types like lambdas ?

  • @prathivar6721
    @prathivar6721 4 місяці тому

    Nice explanation ;)
    but
    on the first hand why does kotlin wt's to do serialisation on navigation , why can't it pass as normal parameter to constructor . fine ;;;;;)

  • @AhmedMeghani
    @AhmedMeghani 28 днів тому

    How can I pass sealed class field as a param?

  • @mikelantzelo
    @mikelantzelo 4 місяці тому

    Why my android studio does not recommend autocomplete like yours ? Thanks for excellent content !!!

  • @animefind5264
    @animefind5264 4 місяці тому

    How navigate inside bottom navigation menu with type-safe

  • @tweeel38
    @tweeel38 4 місяці тому

    Just to confirm, I don't think that feature is available for Compose Multiplatform and nor the type safe navigation, for now at least
    ?

    • @ahmedaaoua
      @ahmedaaoua 4 місяці тому +1

      But voyager available :)

    • @osisuper98
      @osisuper98 4 місяці тому

      Type safe navigation is already available in the last release

    • @tweeel38
      @tweeel38 4 місяці тому

      @@osisuper98 yes but from what I've tried, it still not available in kmp

    • @jackeblan
      @jackeblan 4 місяці тому

      KMP is full of hacks and 3rd party libraries written by a guy from Finland. Not yet.

  • @mudPuddlePanda
    @mudPuddlePanda 4 місяці тому

    Nice

  • @slyene6202
    @slyene6202 3 місяці тому

    Could you please clarify how to create nullable custom types? Because I get an error "Cannot cast ... to NavType. Make sure to provide...". I set nullable in all places where it should be and set isNullableAllowed to true, bui it doesn't work

  • @Abhigyan103
    @Abhigyan103 4 місяці тому

    How to pass view models between screens using this ? Please help

    • @malding1
      @malding1 4 місяці тому

      Why would you want to pass viewmodels?

    • @Abhigyan103
      @Abhigyan103 4 місяці тому

      @@malding1 if I have 3 screens, one start screen, one with show details, one with edit details, how can I edit details without passing the view model ?
      I recently started learning android, this may be basic

    • @manticomar1146
      @manticomar1146 4 місяці тому +1

      @@Abhigyan103 he has another video how to pass share view models between screens its very good

  • @ArthurKhazbs
    @ArthurKhazbs 4 місяці тому

    why `val DogType = object` and not just `object DogType`?

  • @L4szcZ
    @L4szcZ 4 місяці тому

    Why we are using @Serializable and not @Parcelize?

    • @marksunghunpark
      @marksunghunpark 4 місяці тому +1

      It's Kotlin serialization, not Android thing and it's also multi platform supported. I guess they have the support in their mind.

    • @aj3413
      @aj3413 4 місяці тому

      I agree

    • @trungnguyenhuu8184
      @trungnguyenhuu8184 4 місяці тому

      It's kotlin serialization, not Java serializable

  • @pyaesonehan19
    @pyaesonehan19 3 місяці тому

  • @smithshaw1151
    @smithshaw1151 3 місяці тому +2

    What a mess

  • @aihamhammad3074
    @aihamhammad3074 4 місяці тому

    DO NOT USE IT
    I used compose type safe navigation in my production app, alot of crashes that are not rereducable poped up in the compose code so I was'nt able to use try and catch,crash free users and sessions droped, navigation 2.8.0 is not a stable version if u want to use some type safe navigation just convert your object to json and send it.

    • @aj3413
      @aj3413 4 місяці тому

      Yup, plus 2.8 probably doesn't support parcelize. A lot of work needs to be done on it. That is the probable reason this version has a lot of beta releases.