Jetpack Compose Navigation for Beginners - Android Studio Tutorial

Поділитися
Вставка
  • Опубліковано 9 лют 2025
  • In this video you will learn what you need to know about having different screens in jetpack compose and navigating between them.
    ⭐ Get certificates for your future job
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/...
    💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
    elopage.com/s/...
    🎓 Become an industry-ready developer in the Mobile Dev Campus:
    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/...
    This is the navigation compose dependency I used in this video:
    implementation "androidx.navigation:navigation-compose:2.4.0-alpha04"
    Regular programming advice on my Instagram page: / _philipplackner_
    Checkout my GitHub: github.com/phi...
    You like my free content? Here you can buy me a coffee:
    www.buymeacoff...

КОМЕНТАРІ • 148

  • @pixlize
    @pixlize 8 місяців тому +29

    Holy fuck its a 16 step process to go to the next screen and say hello phillip

    • @LuckyFortunes-b3q
      @LuckyFortunes-b3q 3 місяці тому +4

      looks too damn complicated. Every other language including apple it's a few lines of code.

  • @zaryabK-vi8fh
    @zaryabK-vi8fh 2 роки тому +13

    the old nav graph stuff was so easy

  • @Blackops1990
    @Blackops1990 Рік тому +4

    Thx works.
    If the app is crashing for anyone make sure you revert @15:20

  • @dransom90
    @dransom90 Рік тому +3

    Finally, a well-explained tutorial!

  • @edawge
    @edawge 6 місяців тому

    This video helped me set up what i've been trying to do for weeks. I also didn't need the dependency in the build.gradle file. Thank you for this!

  • @farahrayis5928
    @farahrayis5928 3 роки тому +6

    Such a great tutorial, you made compose navigation super easy to understand. Thank you so much. You are an amazing teacher.

  • @thearpansircar
    @thearpansircar 3 роки тому +7

    Loved this explanation, Philipp! Absolutely easy to understand and implement. Tried it out on a project that I've been working on and it implemented beautifully without a single error. Thanks :)

  • @aamirhoda7363
    @aamirhoda7363 7 місяців тому +1

    17:45 you have mentioned you don't realize why that TextField & button stick to the top instead of the center of the screen & the answer to that is that you mistakenly used fillMaxWidth() instead of fillMaxSize() in the Column modifier. 😄😄😄😄
    A very simple thing, learnt it from you only.
    Thank you!

  • @atila_tv
    @atila_tv 2 роки тому +14

    Damm, doing this makes me miss the old Intents.StartActivity, don't you think is too much for just changing from one screen to another?

    • @Pritam252
      @Pritam252 6 місяців тому

      Agreed, but i do wonder if there are any benefits for this much more complicated method, or maybe it's more flexible.

  • @vindoodles7346
    @vindoodles7346 2 роки тому +2

    really wish i could see the whole screen when you're working, it helps for newbs who need to see their way around the application. You have a lot of different folders and setups than I do and so panning the camera all over the application leads to a lot of confusion.

  • @denisshov8518
    @denisshov8518 Рік тому

    Thanks for the dependency in the description so I can just copy-paste. Love your tutorials. Super quality.

  • @jordi5921
    @jordi5921 2 місяці тому

    for those wondering, yes this still works. make sure you're using compile SDK 35 for your emulator

  •  Рік тому

    Hello Philipp ! Thank you for your tutorial. Just watched it after your Jetpack Compose beginner crash course. Very well explained !!

  • @tanjimahmed213
    @tanjimahmed213 3 роки тому +2

    Thanks for your amazing tutorial

  • @stefanusayudha1853
    @stefanusayudha1853 3 роки тому +48

    why wont they make it simpler

  • @samiaghaei1061
    @samiaghaei1061 5 днів тому +1

    hello, I don't have buildscript in my build.gradle(project).
    please someone help me about this problem.

  • @МихаилСеливерстов-э7у

    Man you are the best! Thx for tutorial. For a newbie like me it like a wellspring!

  • @alvaroisea2259
    @alvaroisea2259 3 роки тому

    thanks a lot for your tutorials, definitely among the best teaching android out there

  • @daniyar2718
    @daniyar2718 3 роки тому

    Thanks for a video. Very good explanation.👍😊 Very surprised how navigation works, no need to create fragments, mind blowing 🤯

  • @redleon80
    @redleon80 2 роки тому

    I like your videos man, all of them are very useful..

  • @mehulbisht9708
    @mehulbisht9708 3 роки тому +6

    *Offtopic
    fun fact: earlier Philipp was able to hide her behind his chair when recording in front of his bed but now the green screen made him no longer used to it, so now he has to tilt his camera to hide her 😂😂

  • @UriahHeep-gj5jj
    @UriahHeep-gj5jj Рік тому +1

    Very good tutorial. It is easy to follow and understand; however it is easy only if the user is starting from scratch. I am trying to impliment this tutotrial with the other one you have about the Room database. I have not been able to incorporate both. The 2 tutorials don't seem to be compatible. Perhaps it would help us all if you could make another tutorial where you incorporate bot tutorials. Thank you and keep up the good work.

  • @Kunal-jp8tn
    @Kunal-jp8tn 3 роки тому

    Thank you so much for this simple explanation....

  • @sebastiansopala6295
    @sebastiansopala6295 3 роки тому

    very nicely and clearly explained, great job, thanks !!

  • @utarasama
    @utarasama Рік тому

    Thanks! you helped me a lot

  • @cinnybun739
    @cinnybun739 3 роки тому

    This was awesome!

  • @amirhosseinesmaeili3819
    @amirhosseinesmaeili3819 2 роки тому

    Nice

  • @aleksandrnikolaev2914
    @aleksandrnikolaev2914 Рік тому +1

    So, my application crashes without passing an argument. But But if I use ?name={name} instead /{name} then the application crashes when you pass arguments and when you don’t pass it, it successfully substitutes the default value. What could it be?

  • @droidcasts7350
    @droidcasts7350 3 роки тому

    nice example, thank you

  • @richardwilkinson7873
    @richardwilkinson7873 3 роки тому +1

    As always a great video.
    How do we use the NavButton on any other screen but the MainScreen?? Which navController do we need to import??

  • @josephtorres7091
    @josephtorres7091 3 роки тому

    nice explanation. you can set the varargs type to Any so that it can also accept other data types rather than String types only.

  • @David-zb8br
    @David-zb8br Рік тому +1

    hey philipp, is it possible to share viewmodels between screens using compose navigation? or just primitive types are allowed?

  • @Navak_
    @Navak_ 9 місяців тому

    Ok ok this is great for navigation WITHIN Compose but how do you pass navigation commands from OUTSIDE Compose? The NavHost obeys the NavController but the NavController exists entirely within Compose. I need an external ViewModel to be able to command the NavController.

  • @Hrit
    @Hrit 2 роки тому

    Helpful one, could you make a video on how to navigate between activites?

  • @mojtaba_shafaei
    @mojtaba_shafaei 3 роки тому

    Tnx Phillip, for all of your tuts not just this video.
    Is it possible to add compose to an existing project without refactoring old codes?

  • @khronosium8480
    @khronosium8480 3 роки тому +2

    Hello! Thanks in Advance for this. It helps a lot.
    So Is it safe to say the whole Activity/Fragment as Pages Paradigm can be replaced with this? One Activity is enough to make an app. Say an app contains Auth, Dashboard, Profile, Transactions, etc. ?

  • @mrhacker5476
    @mrhacker5476 3 роки тому +3

    So we should use compose able functions as different screens instead of whole fragment?

    • @PhilippLackner
      @PhilippLackner  3 роки тому +4

      yes

    • @dharmeshbasapati4497
      @dharmeshbasapati4497 2 роки тому

      @@PhilippLackner If we use composables as diff screens then how to manage their lifecycle of each screen(in our case, composables) ?

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

    I'm not sure what the feature is called, if it's part of Android Studio or if it's part of plugin, but can someone tell me how the editor is showing the scope variables (e.g. this: ColumnScope, it: String, etc)? Thanks.

  • @ChrisAthanas
    @ChrisAthanas 3 роки тому

    Im looking in you repo for the source code for this video, and Im not finding it... is it there in a different name?

  • @TheMyth2.9
    @TheMyth2.9 3 роки тому +1

    Good tutorial, thank you so much, it is so much better than the old XML. I am very new to Android Dev`. But I have to say, this is still way too complicated & not very inuitive for a high level framework, especially passing arguments should be much simpler

    • @PhilippLackner
      @PhilippLackner  3 роки тому +1

      well passing arguments works the same way as on the web now. I think with XML it's actually not less complex to deal with Intents and bundles

    • @TheMyth2.9
      @TheMyth2.9 3 роки тому

      @@PhilippLackner Thanks, If I wanted to manage state in ViewModels, would there be one viewModel per screen?
      How would I add state here?

    • @crateer
      @crateer 2 роки тому

      @@TheMyth2.9 well that depends on your architecture. You can have one ViewModel per Screen, or a single one for all Screens. Obviously one ViewModel per Screen is cleaner. I hate to say it, but it’s true as always: it depends 😂
      For state just use LiveData as usual, then handle them in your Screens

    • @ahmadh9381
      @ahmadh9381 2 роки тому

      ​​@@PhilippLackner , Hello sir,
      can you do a video on how to navigate between different screens by inputting voice.
      For example the user should talk to the application and if for example the user say "next" the app should move to the next screen and if the user say "back" the application should navigate to the previous screen
      I can't find this information anywhere on the internet.
      Thanks sir, Hope you respond to me quickly please

  • @RagHelen
    @RagHelen 10 місяців тому

    Does the classical way without Jackpack require a similar convoluted mess?

  • @rezazavareh4899
    @rezazavareh4899 Рік тому

    Hi Philipp, I implemented it but have a problem with recomposition after getting data from the view model and navigating to the next screen and not find right solution

  • @tristanrentz7687
    @tristanrentz7687 2 роки тому

    As I engage it, this tutorial is a year old.... I'm experiencing NO END of build issues. Please please please Philipp, thinking back and knowing all that you know, what can you give me to simplify this nightmare so that I can complete the tutorial with my sanity intact and my blood not on my walls? PLEEEEEEASE HELP

  • @xavierrispal9605
    @xavierrispal9605 3 роки тому +6

    Hello Philipp and thanks for this interesting video. Have you tackled a little bit the topic of screen transition animation which was pretty easy in navigation components but seems to be much much harder in Compose ?

  • @joshrose9987
    @joshrose9987 3 роки тому

    Hey Philipp, how do you make it so that when you select a method from the autocomplete dropdown, the method argument keywords appear too?

  • @st4849
    @st4849 3 роки тому

    How can I deeplink into a specific screen in this single-activity scenario please? Can the NavHost be instructed to map a deeplink to a route? (I presume the Activity needs to be set up to receive all possible deeplinks in some way for this)

  • @alexissuarezalvarez5622
    @alexissuarezalvarez5622 2 роки тому

    Hi, I am starting with android, and I have a query Is navigation similar to using Intent in android?

  • @dmytromarchuk3023
    @dmytromarchuk3023 3 роки тому +2

    What is happening with the screen A when we open screen B? A->B
    We used to think that it will be stored somehow and will be restored once we press back.
    But since Compose is function of a state, it will free up all the resources of the screen A and will be composed again when we go back.
    Is that correct?

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

      exactly. the lifetimes of those "remember" things are not obvious at all

  • @juanfrancisco9039
    @juanfrancisco9039 3 роки тому

    Philipp, have you tried navigation from a page inside an HorizontalPager?

  • @shaikhshafeen
    @shaikhshafeen 6 місяців тому

    I always end up here looking for understandable tutorial 😂

  • @harisai3580
    @harisai3580 2 роки тому

    Philip why you have made the media queries video private. please make it available

  • @Vl-TV
    @Vl-TV 2 роки тому

    tnx bro

  • @Alex-ve4wr
    @Alex-ve4wr 3 роки тому

    Helpful

  • @DraskoSaric
    @DraskoSaric 3 роки тому +2

    Why don't you use graph? It is more visible when you have all drawn on one place.

  • @talhashaikh1435
    @talhashaikh1435 3 роки тому

    Can we develop the same using NavGraph ? and if so what changes we have to make in gradle file

  • @ahmadh9381
    @ahmadh9381 2 роки тому

    ​@Philipp Lackner , Hello sir,
    can you do a video on how to navigate between different screens by inputting voice/speaking using jetpack compose
    For example the user should talk to the application and if for example the user say "next" the app should move to the next screen and if the user say "back" the application should navigate to the previous screen
    I can't find this information anywhere on the internet.
    Thanks sir, Hope you respond to me quickly please

  • @mindfulnessrock
    @mindfulnessrock Рік тому

    What's the second "build.gradle JetpackNavigation" file is all about?

  • @danielmwinzi9223
    @danielmwinzi9223 2 роки тому

    Is it a bad practice to use intent when navigating to another screen

  • @h.k3260
    @h.k3260 2 роки тому +1

    How come theres nothing in the Main activity file?

  • @meigarajuma
    @meigarajuma 2 роки тому

    How if the string argument that we want to pass contains slash "/"? Is it read as an argument separator?

  • @skr4tchnen335
    @skr4tchnen335 3 роки тому

    hey philip do you have any idea how we can listen to viewmodel livedatas with jts ui state in jetpack compose?

    • @PhilippLackner
      @PhilippLackner  3 роки тому +2

      you can convert live data to compose state with the function observerAsState() I think

    • @koczmen22
      @koczmen22 3 роки тому

      @@PhilippLackner What about observing one-time events emitted by SharedFlow?

  • @ajay-ri7ex
    @ajay-ri7ex 2 роки тому

    What is the best way to pass bitmap between composoble screens

  • @mayanknagwanshi
    @mayanknagwanshi Рік тому +1

    so the app is now a single activity?

  • @dmytromarchuk3023
    @dmytromarchuk3023 3 роки тому

    Is there any way to implement nested navigation?
    I tried to do this for a single tab by using navigation instead of composable function, when defining NavHost, but when it was buggy.
    Example:
    A-B-C - 3 bottom bar tabs
    I go to B->B1->B2
    Then go to A
    Then go to B
    I expect to see B2 route, but it is B
    Passing a different NavController to a nested graph leads to a crash "ViewModelStore should be set before setGraph call"

  • @peterjcspencer
    @peterjcspencer 2 роки тому

    Great video! But all this to simply navigate between two screens, having to pass string args...

  • @abhay2192
    @abhay2192 3 роки тому +5

    Please sir🙏🙏🙏make a video illustrating the use of architectural pattern in jetpack compose

    • @PhilippLackner
      @PhilippLackner  3 роки тому +1

      Did that in my pokedex Playlist

    • @Someone-q6f5x
      @Someone-q6f5x 3 роки тому

      No, beg harder

    • @abhay2192
      @abhay2192 3 роки тому

      @@PhilippLackner maybe, (didn't want to say that) it was not that explanatory 🥺

  • @neilloncesar5219
    @neilloncesar5219 3 роки тому

    There is any other solution to pass Parcelables as parameters using Jetpack Compose? The two I end up were to use Json or put parcelable directly on the backStack

  • @tavindersingh8185
    @tavindersingh8185 3 роки тому

    Hi, Can you tell me how to create a new launcher activity in jetpack compose?

  • @DanOfYT
    @DanOfYT 5 місяців тому

    I tried running my app with name as an optional argument like you showed, and my app was crashing. Could not figure out for the life of me what was doing it. Then I realized - the helper function was still creating the route with the required argument syntax.

  • @bodormarcel4373
    @bodormarcel4373 Рік тому

    Here is probably the main "pain" in android/kotlin/compose family.
    Your nice example does not work anymore with an actual version.
    I was trying to implement it for two hours or so... errors, errors... Gradle info's are no longer available etc... a real mess.
    I don't blame you. To the contrary, your made an excellent job... but as two of my books : they are obsolete after a very short while.

    • @Blackops1990
      @Blackops1990 Рік тому

      Works for me. In the gradle make sure you have the updated nav implementation, you don't need to do anything in the Project grade.
      also @15:20 make sure you revert to "/{name}" or the app with crash on button click

  • @mahendranv6264
    @mahendranv6264 3 роки тому

    How to use github libraries views which those included in xml file in a jetpack compose...?

  • @Rafael-hk9pg
    @Rafael-hk9pg 3 роки тому

    How about conditional routes when the user authenticates?

  • @Spham99
    @Spham99 2 роки тому

    If anyone an answer this, that would be great!
    So Jetpack Compose is like navigating between different "screens" (AKA fragments) on one singular Activity?
    Also anyone else having issues with the
    'rememberNavController()'? Im getting IllegalStateException there ...

  • @kamildoan
    @kamildoan 3 роки тому +1

    Really nice content. I am wondering why jetpack navigation doesn't have animation when routeing another page

  • @Albert-Dyck
    @Albert-Dyck 10 місяців тому

    3:55 sealed class missing in Android studio Iguana. What now?

  • @umaralfaruq1304
    @umaralfaruq1304 2 роки тому

    How to add transition like opening and closing activity?

  • @narendragupta3204
    @narendragupta3204 3 роки тому

    Do u have any examples for below scenario
    Graph_A--->F1,F2,F3.
    Graph_B--->F4,F5,F6
    So I need to lunch F5 from the F2 with passing data .

  • @MrNik-zv7dp
    @MrNik-zv7dp 2 роки тому

    JetCompose dropdown . with only icons . no text. do we have that in android ? Icon Drop down ?

  • @halvtysk
    @halvtysk 2 роки тому

    Great guide and presentation, but as I'd never heard of "Compose navigation" before, I was really confused about the steps behind the development of this feature. To me, it feels like taking steps backwards from the "Jetback Navigation" way of navigating. The lack of a navgraph (xml) and the fact that you pass arguments almost like a url feels like a huge disadvantage to me? You lose all the type safety and ease of use that you get from using safe-args, and you also have to "re-invent the wheel" with regards to setting up navigation. I don't really see the benefit of using this over "default" jetpack navigation? Unless you (for some reason) really dislike writing xml, I don't see any immediate connection/benefits to this way of merging the worlds behind navigation and compose? Am I missing something?

    • @PhilippLackner
      @PhilippLackner  2 роки тому

      Nope, you're right, the normal navigation for Compose is pretty bad. That's why I typically use the Compose Nav Destinations library for that which makes this a lot easier

    • @halvtysk
      @halvtysk 2 роки тому

      @@PhilippLackner I found that video a couple of minutes after writing my comment above, so I'll spare my judgement until I've finished that video. :)
      But:
      I still can't understand what the benefits are compared to just using "normal" navigation? A library that improves it is great, but if it forces you to use third party library, it feels like you're back to the times before Jetback navigation where every developer had their own self-written or third-party library handling navigation. It might be a personal preference, but I'd prefer *less* fragmentation between apps. As it is now, library or not, I still can't see the benefits to either Compose or navigation in general to using this?

  • @jiananli9507
    @jiananli9507 Рік тому

    Thanks for explaining ❤. I am an iOS developer. It’s still complicated than SwiftUI.😮

  • @mrbmro3991
    @mrbmro3991 2 роки тому +2

    Tons of boilerplate just to send an argument from one screen to another? Android developera need to rethink this

  • @AbhishekPal-ri9gr
    @AbhishekPal-ri9gr 3 роки тому +2

    Can you make a video of android development roadmap

    • @PhilippLackner
      @PhilippLackner  3 роки тому +9

      no I'm not a friend of roadmaps. Just learn the basics and build projects. You'll learn everything necessary on the fly

    • @voidpointer398
      @voidpointer398 3 роки тому

      @@PhilippLackner thank you for specifying the way

    • @iam-learning6374
      @iam-learning6374 3 роки тому

      follow his tutorials, you will rock :)

  • @farazahmed7
    @farazahmed7 2 роки тому

    It seems that we wont be needing fragments now.
    But do the compose pause when it is in background and another compose screen comes in foreground ?

  • @shibabasensei6219
    @shibabasensei6219 3 роки тому

    The project is using an incompatible version (7.0.0-alpha05) of the Android Gradle plugin.

    • @fauxvillage3811
      @fauxvillage3811 3 роки тому +1

      perhaps you can try version 7.1.0-alpha03 (when in alpha, they tend not to continue serving the previous releases, so the ide reports it not being available...), and perhaps also kotlin-gradle-plugin:1.5.10 which seemed to be required for on my androidstudio bumblebee ide

    • @shibabasensei6219
      @shibabasensei6219 3 роки тому

      @@fauxvillage3811 classpath 'com.android.tools.build:gradle:7.1.0-alpha03'
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
      thanks working

  • @fernandomtz8177
    @fernandomtz8177 11 місяців тому

    Im getting an error when i make this:
    NavHost(navController= navController,startdestination = Screens.Mainscr.route){
    composable(route = Screens.Mainscr.route){
    Mainscr(NavController = navController)
    }
    Says i have to create composable function. Can anyone help?
    I may be missing a gradle implementation but idk.

  • @mehranj73
    @mehranj73 3 роки тому

    What about our own objects? How can I pass them?

  • @commonsense1019
    @commonsense1019 3 роки тому

    Hello idk why but I am not able to get the alignment part right

  • @kennardsugirotok7374
    @kennardsugirotok7374 2 роки тому

    Can you pass a mutable state?

  • @abuiman5251
    @abuiman5251 3 роки тому

    Dear Philipp,
    I am sorry that my comment not related to this topic, but could you please show how to implement real ERASER TOOL using PotterDuff.Mode in Drawing App, not just setting white color or any other color equal to background color. I've been stuck with this issue for a long time and cannot find any solution in Kotlin. PLEASE help if it is possible. I will be really grateful!

  • @ultimat.
    @ultimat. 3 роки тому

    Je voudrais qu'une. Liste d'items ouvre d'autres liste de divers catégories avez vous des tutos ou des liens qui pourrait traité mon sujet , merci

  • @harisai3580
    @harisai3580 2 роки тому

    I think with intents it seems a bit easy

  • @ZaidZakir
    @ZaidZakir 3 роки тому

    fillMaxSize() to fix the alignment of main screen

  • @CorneliusJubril
    @CorneliusJubril Рік тому +4

    fucking hell! just to switch from 1 screen to another. XML was better 😑

    • @Luffy_2804
      @Luffy_2804 Рік тому +1

      fr 😂 they just fucked up jetpack

  • @mariofeles1
    @mariofeles1 3 роки тому

    how to pass parcelable without navigation? @Philipp Lackner

  • @codingwithsam4992
    @codingwithsam4992 3 роки тому

    Please upload the github repository of this

  • @benarjee9777
    @benarjee9777 2 роки тому

    it is getting complex with compose for passing nav arguments

  • @brianryan4053
    @brianryan4053 3 роки тому +1

    Intents deprecated ? ?. ?: !!

  • @denisk3852
    @denisk3852 3 роки тому

    Why did Google do navigation with no simple sending of parameters: strings, numbers, objects? It’s boring to send arguments not directly.

  • @zohaibraza1365
    @zohaibraza1365 3 роки тому

    Very Nice Explanation.
    Although i have a question.
    I have a Main Screen Composable, inside of which i have defined NavHost and Routes. Now i have Navigation like this :
    Main Screen -> License Listing Screen -> License Detail Screen
    But Issue is when i use navigate(":License Detail Screen") from inside of "License Listing Screen", then Listing Screen gets removed from stack. But i want this Listing Screen to stay right there. But currently when navigate to Detail Screen it pops out the Listing screen and It's Exit Animation is displayed.
    It would be awesome if you ping some comments on this.

  • @eltoro_study
    @eltoro_study 3 роки тому

    Супер.