The ULTIMATE Guide to Sharing Data Between Screens in Jetpack Compose

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น •

  • @mohamadkhorsandi6103
    @mohamadkhorsandi6103 5 หลายเดือนก่อน +1

    man, let me say you something
    you are the hero
    as a beginner quite often i get confused
    and watching your videos is the ONLY solution

  • @Wiggy90210
    @Wiggy90210 ปีที่แล้ว +4

    I like using raamcosta destinations for compose, it really makes things easy. It alow passing data between @Composable's, but after this I can initialize my ViewModel with the value.

  • @seannatv
    @seannatv ปีที่แล้ว +4

    Another "con" of using navigation arg is that you need to make sure the string is URL encoded. I said con with quotes because you can handle this pretty easily, but sometimes you forget to do that and can spend significant of time to find out why something isn't working as expected.

    • @igormorozov6311
      @igormorozov6311 ปีที่แล้ว

      you are right. By the way, Philipp didn't mentionate this and I am curious: is navigation arg only one way for using callBacks? thanks

  • @vengateshm2122
    @vengateshm2122 ปีที่แล้ว +2

    Hi Phillip,
    Can we have shared viewmodel and individual viewmodel for on one onboarding screen composable at same time?

  • @saeidhonardan
    @saeidhonardan ปีที่แล้ว +2

    It is great that put the source code of the video. thanks

  • @MatthewSmith-mt3kz
    @MatthewSmith-mt3kz 10 หลายเดือนก่อน

    Great tutorial, gave me a couple of good ideas for my own implementation. Thank you.

  • @MrCinekDBW
    @MrCinekDBW ปีที่แล้ว +2

    That's exactly what I needed! Thanks a lot

  • @csmuthukuda916
    @csmuthukuda916 ปีที่แล้ว +2

    How can we share a value between main activity and a compose secreen in a different feature module..value is defined in main acitivity and i want to get it from the composable

  • @Flea997
    @Flea997 4 หลายเดือนก่อน

    what if I want to use navigation arguments to navigate to a screen that used a shared view model? It looks like that the saveStateHandle is not updated with navigation argument being it associated to the root of the graph

  • @tomsam2417
    @tomsam2417 ปีที่แล้ว +5

    Hi Philipp. Very helpful video as always. I have a question: why are you using shared preferences instead of data store?

    • @ctcat4950
      @ctcat4950 ปีที่แล้ว +11

      Because the API design of the shared preference is much more simpler than data store. So that this video can focus on the topic (instead of a lot of unnecessary unrelated code), I guess.

  • @inno_san
    @inno_san ปีที่แล้ว +2

    I am using hilt view model with compose destinations, pretty neat

  • @legato0
    @legato0 ปีที่แล้ว

    Thanks for sharing your knowledge 👍. As a beginner, I always used the first option to pass parameters between views. Now I can start testing different ways 😄

  • @SiamakAshrafi
    @SiamakAshrafi ปีที่แล้ว +1

    Nice. Very clear 🙂

  • @amrel-tahhan8588
    @amrel-tahhan8588 ปีที่แล้ว +1

    I really love the way you demonstrate thing ♥
    but I think you should add the video to the compose playlist so we can find it easily

  • @suchizgames4748
    @suchizgames4748 ปีที่แล้ว

    Hi, thanks for enlightening me. I am using DaggerHilt in a Jetpack Compose project with nested graph. So I chose to share a viewmodel which is graph scoped. But I am struggling to inject that sharedViewmodel into "children" viewmodels. Is there a way of doing this ? thanks

  • @starry_shivam
    @starry_shivam ปีที่แล้ว

    Helpful as always, Thanks!

  • @techug2719
    @techug2719 9 หลายเดือนก่อน

    Help:
    It has been an increasing trend to have routes stored in a sealed class as objects, i am having trouble following up using my own code base because when i call the route i find it difficult to add the parameter i am passing as i am navigating, how can I do this?

  • @JohanAlbrectsen
    @JohanAlbrectsen ปีที่แล้ว +2

    I'm sharing a viewModel between a regular composable and a sheet, but the UI doesn't update when I change the sharedState in the viewModel from the sheet. How can I make it recompose when the value in the viewModel is updated?

    • @JohanAlbrectsen
      @JohanAlbrectsen ปีที่แล้ว +3

      Resolved, used mutableStateOf instead of MutableStateFlow, for anyone wondering 😁

    • @helloworld_sw
      @helloworld_sw ปีที่แล้ว

      @@JohanAlbrectsen why MutableStateFlow didn't work

  • @androidkotlin-6234
    @androidkotlin-6234 ปีที่แล้ว +1

    how can I pass nullable value? for example, I need to pass Long (as LocalDateTime), and sometime this value can be nullable. If I pass null for that value, my application is crashing, because it's an exception about wrong navigation, can't find route

    • @excalibur8147
      @excalibur8147 ปีที่แล้ว +2

      At the function call who gets nullable value, make it nullable and assign a value if null with " ?: "
      fun getTime(nullableVariable: Long ?: 0)
      Or before using nullable variable, check if it is null
      if (nullableVariable != null) {
      //do if not null...
      } else {
      //do if null...
      }

  • @craigberry5713
    @craigberry5713 ปีที่แล้ว +1

    Hi Philipp, first thank you for the great tutorials.I have a question if you have time?
    In the last (persistent storage) example, if we want to clear the session every time the application is closed / destroyed, but we want the session to persist through the lifetime of the app, where is the appropriate place to clear it? Isn't onDestroy() called sometimes during process death?
    Thank you again!

    • @igormorozov6311
      @igormorozov6311 ปีที่แล้ว +1

      hi, this is not onDestroy(), look at 21:11, he is using fun clearSession(). Philipp told he call this functions when he need to log out

  • @emmanuelmtera5936
    @emmanuelmtera5936 ปีที่แล้ว

    On the last option is using sqDelight a choice for Kotlin Multiplatform Mobile?

  • @nourmorgan6751
    @nourmorgan6751 ปีที่แล้ว +2

    Hey Philipp , what about using compose destinations ?

  • @vinaykumarpatel649
    @vinaykumarpatel649 ปีที่แล้ว +2

    In my current organization we use Singletons inside Repository to share users login data between different viewmodels, and they never experience any issue with that. I still don't understand why are you saying to avoid using Singleton classes to share data between. It is usuful when we need to access user's details in different pages.

    • @aroxing
      @aroxing ปีที่แล้ว

      Android Studio always raises warnings about memory leaks using Singleton. I'm also curious why they suggest using Singletons but at the same time warn about memory leaks.

    • @antonhelsgaun
      @antonhelsgaun ปีที่แล้ว

      ​@@aroxinghow does using a singleton leak memory? Isn't the whole point that it doesn't?

    • @aroxing
      @aroxing ปีที่แล้ว

      @@antonhelsgaun Ask Android API and Android Studio creators

    • @PedroBarbosaRoman
      @PedroBarbosaRoman 4 หลายเดือนก่อน +1

      @@antonhelsgaun I think that they mean that you might overuse singletons when they are not needed every time. If you use for example a singleton for a form, when you are in other parts of the app that singleton is still there using memory. However this can be mitigated by the use of scopes in the dependency injection framework.

  • @trp4871
    @trp4871 ปีที่แล้ว +1

    Hi Philipp, I have a question about docker. Do we (android dev) need to learn docker or it just nice to know

    • @Latsson2
      @Latsson2 ปีที่แล้ว +2

      No you don't

    • @ChrisAthanas
      @ChrisAthanas ปีที่แล้ว +1

      Not needed for android dev
      It’s a backend tech

  • @alexmercerind
    @alexmercerind 9 หลายเดือนก่อน

    Does composition local work through configuration changes?

  • @РинатФ-я7о
    @РинатФ-я7о 11 หลายเดือนก่อน

    Hey Philipp. How to pass arguments to shared viewmodel?

  • @arielapp9469
    @arielapp9469 ปีที่แล้ว +3

    I wish there was a better way of writing jetpack navigation better :\
    anyway thank you for this lovely guide.
    is there a difference between @Singleton and object in kotlin?

    • @ChrisAthanas
      @ChrisAthanas ปีที่แล้ว +1

      No, just one is for hilt annotation processing and the other is built into the language

  • @siyabulelashabalala8963
    @siyabulelashabalala8963 ปีที่แล้ว +1

    Hi Philipp, love your videos. I have a question here, in your few previous videos you use raamcosta library as a navigation tool and lately I've seen you stop using it and I saw it also seems to provide an easy way to share data since it can share reference data. What disadvantage you discovered that made you stop using it?

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว +4

      I didn't stop using it, but I want my videos to be helpful for as many people as possible so I also use the official practices for such videos

    • @siyabulelashabalala8963
      @siyabulelashabalala8963 ปีที่แล้ว

      ​@@PhilippLackner cool thanks, one more question. Why do you use sealed class when a sealed interface can do the job? Especially on the event rapper class where the classes inside the sealed class share no common data unlike the Resource class

  • @moisesvalera3597
    @moisesvalera3597 ปีที่แล้ว

    In SharedViewModel approach, how can I reset the viewModel once I leave "personal_details" route?, it's always loading previous data onceI got back into it again.

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว

      The whole graph needs to be popped from the backstack to clear it

  • @the_nomadic_ajith
    @the_nomadic_ajith ปีที่แล้ว

    One question, why do we have to redeclare a new mutable state in viewmodel and assign it to original stateflow. Is there any issue if create a stateflow in viewmodel and directly access it from composables? As long as i make sure that i am not writing anything to the state, is it fine?
    Ref: private val val sharedState = MutableStateFlow( value: 0)
    sharedState = _sharedState.asStateFlow)

    • @JepRM
      @JepRM ปีที่แล้ว +2

      That .asStateFlow() returns the stateflow as immutable. So the visible sharedState is immutable. This enforces that there is a single source of truth for that view state as only the view model can update it. This is something jetbrains said would be improved at some point in kotlin 2 🤞

  • @khatteeeer_Dev
    @khatteeeer_Dev ปีที่แล้ว

    How can we make favorite item to database and when colse app and run it again the fav button will be active based on database ?

  • @kevalkanpariya
    @kevalkanpariya ปีที่แล้ว +1

    Please make video on Oauth2 Authentication with Webview using Jetpack compose
    How the CallBackUrl retrieved from the api and retrieve access token to make api calls.

    • @ayodelekehinde
      @ayodelekehinde ปีที่แล้ว

      Well you can't use WebView for oauth due to security reasons. But you can use custom tabs.

    • @kevalkanpariya
      @kevalkanpariya ปีที่แล้ว

      @@ayodelekehinde can tell me about more

    • @ayodelekehinde
      @ayodelekehinde ปีที่แล้ว

      @@kevalkanpariya On how to use custom tabs??

  • @mubashirpa
    @mubashirpa ปีที่แล้ว +2

    How to pass data to the previous screen
    Eg: I have two screen first screen is to show the list of some items from database and second screen is used to create an item. When I create an item from the second screen I want close that screen and show the updated list in the first screen

    • @Polite_person_
      @Polite_person_ ปีที่แล้ว

      ActivityResultApi

    • @JakkeJakobsen
      @JakkeJakobsen ปีที่แล้ว +1

      Viewmodel with stateflows should work for this

    • @osisuper98
      @osisuper98 ปีที่แล้ว

      Save to db on the second screen and observe latest changes from the first screen by calling room again. Make sure your dao function, if dealing with a list for example, emits a flow. That makes it easy to read latest db items without any hassle.

  • @Prakhar1701
    @Prakhar1701 ปีที่แล้ว

    can any one tell me how to pass a custom model class object with navigation and what Navtype should i use, please help me

  • @aviator1472
    @aviator1472 10 หลายเดือนก่อน

    14:12 why not to use Object?

  • @khayyamaurelius912
    @khayyamaurelius912 8 หลายเดือนก่อน

    Great video

  • @chelfe
    @chelfe ปีที่แล้ว

    does passed intent arguments survive process death?

  • @BigCarso
    @BigCarso 2 หลายเดือนก่อน

    Global Singleton would be perfect for login state imo

  • @eibaal-gx9os
    @eibaal-gx9os ปีที่แล้ว +1

    When you try jetpack compose multiplataform ?

  • @AsadKhan-et9ux
    @AsadKhan-et9ux ปีที่แล้ว

    how to use hilt shared viewmodel

  • @sanky52
    @sanky52 ปีที่แล้ว

    How to send parcelable object to start destination

  • @itsjee9700
    @itsjee9700 ปีที่แล้ว

    Can we share complex object data without using SharedViewModel ?

  • @neronguyenvn2
    @neronguyenvn2 ปีที่แล้ว

    how to properly share with activity please tell me

  • @VictorFarkas-fp2gl
    @VictorFarkas-fp2gl ปีที่แล้ว

    what about Preferences DataStore?

  • @SpaceGuideHub
    @SpaceGuideHub ปีที่แล้ว

    It seems to me that data binding in xml layout projects is easy, but it more hell then compose

  • @danilsveticov6196
    @danilsveticov6196 ปีที่แล้ว

    Thanks

  • @thedarkknight1865
    @thedarkknight1865 ปีที่แล้ว +12

    I use bundle

  • @seanknowles9985
    @seanknowles9985 ปีที่แล้ว

    In what order shall we take all your courses?!

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว

      They don't depend on each other, so as you like 👍🏼

    • @seanknowles9985
      @seanknowles9985 ปีที่แล้ว

      @@PhilippLackner legend will let you know when I am done! Also, would be super cool to get some discount on your monthly subs for the freelancer group for those who bought the ultimate package:) just saying..

  • @huddahhuddah517
    @huddahhuddah517 ปีที่แล้ว

    Im still hard to understand navigation in compose :(

  • @mahmoudalkateb2008
    @mahmoudalkateb2008 ปีที่แล้ว +1

    🎉

  • @amansingh.h716
    @amansingh.h716 2 หลายเดือนก่อน

    flutter is best to send data from one screen to other

  • @tuyulghost291
    @tuyulghost291 ปีที่แล้ว +5

    your english so fast, please make it slow

  • @Adam0001
    @Adam0001 ปีที่แล้ว

    Hello Mr.Pilipp
    Could you make an app with multi-module and navigation, and the app consists of two types of user.
    Thanks a lot 🤍

  • @seanoh1989
    @seanoh1989 ปีที่แล้ว +6

    Another "con" of using navigation arg is that you need to make sure the string is URL encoded. I said con with quotes because you can handle this pretty easily, but sometimes you forget to do that and can spend significant of time to find out why something isn't working as expected.

    • @osisuper98
      @osisuper98 ปีที่แล้ว +4

      I once spent 3hrs on this little thing. Very painful experience.

    • @ChrisAthanas
      @ChrisAthanas ปีที่แล้ว +2

      I got snagged on this early on
      They should have made it some kind of standard hint

  • @John-qt6qk
    @John-qt6qk ปีที่แล้ว

    Thanks