Тёмный

Kotlin Flows in practice 

Android Developers
Подписаться 1,3 млн
Просмотров 155 тыс.
50% 1

With coroutines as the recommended solution for asynchronous operations, Kotlin Flow is the obvious choice for managing streams of data in Android apps. However, there are some lifecycle perils to consider and new lifecycle-aware APIs to understand in order to get the most out of Flows in Android. Learn about the powerful and expressive Flow APIs and how to use them across all layers of your app in a practical way-solving common use cases every developer can face.
Resources:
Kotlin flows on Android → goo.gle/3AXlXFi
Official Android Developers publication on Medium → goo.gle/3lUhY8o
Google I/O app source code → goo.gle/3ji3AFe
Speakers:
Manuel Vicente Vivo, Jose Alcérreca
Watch more:
Watch all the Android Dev Summit sessions → goo.gle/ads21-allsessions
Watch all the Modern Android Development sessions → goo.gle/ads21-mad
Subscribe to Android Developers → goo.gle/AndroidDevs
#AndroidDevSummit, #Kotlin #Featured #Latest
product: Android - Languages; event: Android Dev Summit 2021; fullname: Manuel Vicente Vivo, Jose Alcérreca; re_ty: Publish;

Наука

Опубликовано:

 

26 окт 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 84   
@karthikss6501
@karthikss6501 2 года назад
Wow. Its really amazing to see coroutine has evolved in different level now a days. Kudos to the team🙌🏻
@MuhammadFarhan-pq2wc
@MuhammadFarhan-pq2wc 2 года назад
Wow, that's an Amazing session of Basic understanding of Flow and State flow in the easiest form. very much needed this content because of the dilemma of Flow and Live data and what is flow where to start. Thanks for the great content Liked it very much.
@jonneymendoza
@jonneymendoza Год назад
Wait till you hook up state flows with composable screens. match made in heaven
@deepakbisht4957
@deepakbisht4957 2 года назад
What an amazing video! Thanks for the examples you were using they were very clear and adding lifecycle diagram is a top of the cherry...
@thecsciworker291
@thecsciworker291 2 года назад
Wow. Really took a concept and broke it down. Thank you for this!
@vengateshm2122
@vengateshm2122 2 года назад
Excellent content. Good to see that life cycle related pain points are addressed elegantly.
@chuka_obi5167
@chuka_obi5167 2 года назад
This was an awesome tutorial on flows! Thank you
@ILikeActions
@ILikeActions 2 года назад
Amazing content, thank you very much to provide material that it so easy to be understanded!
@thiagolopessilva
@thiagolopessilva 2 года назад
Excellent content. Thanks to share it with us and now I can understand flow in Android context.
@hoonjung2143
@hoonjung2143 2 года назад
Muchas gracias! Good stuff and well explained! Keep on the good work. Thank you :)
@HaSeebpjr01
@HaSeebpjr01 6 месяцев назад
best toturial ever i watch about Flows
@thomasknee7844
@thomasknee7844 2 года назад
Great video, very informative and helped me understand things much better
@theredd1703
@theredd1703 9 месяцев назад
Love it the interactive way you did the video!
@omkarpawar1741
@omkarpawar1741 Год назад
can you explain the difference between statein(.... , whilesubscribed(5000) ) and collectAsStateWithLifecycle () are they supposed to do the same thing, because whilesubscirbed waits for 5 seconds ?
@goobar
@goobar 2 года назад
Great work with this one guys!!
@anteckoeros
@anteckoeros 2 года назад
Yeah nice video and Pancho is the best example, thank you :)
@ranganrangan5633
@ranganrangan5633 2 года назад
If we use repeatOnLifecycle in activity, then importance of ViewModel likely less. So this example s just for illustration or really we don't need viewmodel anymore?
@nima7605
@nima7605 Год назад
Very helpful with an excellent explanation
@navczydev
@navczydev 2 года назад
Great talk thank you folks
@megaxenu753
@megaxenu753 11 месяцев назад
surprisingly this video actually helped.
@xeon3325
@xeon3325 Год назад
Very vivid explanation of the article
@Padpaad
@Padpaad 2 года назад
nice presentation about the flow!!
@dithyramb6152
@dithyramb6152 Год назад
Thank you! You've helped me solve a lot of problems!
@AndroidDevelopers
@AndroidDevelopers Год назад
You are so welcome 😀 We're pleased to hear this has helped you on your Android journey 🛤️
@jeffreynyauke7636
@jeffreynyauke7636 2 года назад
Nice video. You should cover Flows using Jetpack Compose
@kreutzerzetanism7396
@kreutzerzetanism7396 Год назад
this seems so seamless
@schinsky6833
@schinsky6833 2 года назад
10:46 This part I dont understand. Why is live data considered "adding another technology to the mix" (implying its not ideal), when before you said its lifecycle aware and perfectly fine?
@Mrdresden
@Mrdresden 2 года назад
Very informative, thanks!
@AndroidDevelopers
@AndroidDevelopers Год назад
Delighted to hear this! Have you checked out the documentation for Kotlin Flows on Android?: goo.gle/3AXlXFi Happy learning! 😎
@hichaam2
@hichaam2 2 года назад
Thanks for the content, but I think there should be a clearer and a not breaking migration path from LiveData, the current suggestion of replacing `asLiveData` with `stateIn(WhileSubscribed(5000))` and `repeatOnLifecycle` won't give the same result, since the whole Flow chain will be re-executed when the apps comes from background, and this wasn't the case with `asLiveData`
@hichaam2
@hichaam2 2 года назад
@@manuelvivo9276 Thanks for the reply, the difference is that `asLiveData` won't restart the flow if it has been completed (since it uses the builder `liveData` under the hood), unlike the combination of `repeatOnLifecycle` + `stateIn(WhileSubscribed(5000))` which would restart the Flow everytime the app comes from background whatever the status of the upstream Flow. So for long-living Flows: observing a database, or observing location updates..., there is no difference, but when the Flow is emitting a limited number of results (just fetching something from an API for example), using the new API, we will end up running it more than needed, we can solve this by using an intermediate `MutableStateFlow` to hold the results, instead of directly exposing the cold Flow, but in the video, you said that this solution is not reactive enough :)
@hichaam2
@hichaam2 2 года назад
@@manuelvivo9276 or we can keep using `launchWhenStarted` for those cases, since when using `Eager` or `Lazy` the upstream Flow will stay active in all cases, and the repeatOnLifecycle won't have any effect on it, instead it would just cause re-emitting the last value each time the app becomes active another time, and would cause some not-needed redrawing, so `launchedWhenStarted` would save more resources on this case. Anyway, I think this scenario should be clarified in the docs, thanks again for the replies 🙏
@lalesaboori4353
@lalesaboori4353 2 года назад
تگنتتلتتتببببببتخبلتتبتتتتتتتتهتهبتتتختختا/88 ج/یالان إثخاأاآخااآآخااهاالتاالیتکیاثااتاتااالآاآحتلیآاالااعاتاتااااهاعاااعاااااتاااالهااعاخااالااااهاااااااالاعحاااالاتااهاااااااااخاخاتاااااااههااااخااهخهاهااختااخاااهااااهخااالااالاااالااااااااااهخااااالاهلهااهااااالاااااالالتاااااهاااالهااااتمخاتاهاعتاااااخاااهاااالالللاخخاهالخااهالاااهاهااااخلاعاتهلااههااخاااااخالختهااااالاهاااالاالاااهاااااللاالاااااخهااااااااالخهاهااهااااااااااااهااااااااااهاهلااااااااااخالااااالاااهااایاهاااااااااااخاخااهاالاااخاالاااهلعاهاهالااالاااااهالاااللاااااهلاااهااخااااالاهاالاااهاااااااهاهااهاااااااالاااهاااالااهااهاااااااااالالااااالااهاهههاهاخاااااللهاهاااااااااااالاایااااااااهلااااااااایااالاااللاعههععهااااهااااااهلاااااالاعااعااااهلاااعلاالعااعاخلااهااااااااااالالااخاالاااهالاااااااهخاهخاالاااالاهااااالاخلهعالالااههااااخالایاالکالاااهاااخالایااااااااااعااالالاااخلالاللعاالهالاااااییاخاخلاالاهااهااااااهعااخلالاعهایاااااححاااکهااایاهااااهاااعلاااههااااااههیهاااااااااهاهاااااااهایخااخئس
@arunjoseph662
@arunjoseph662 2 года назад
​@@hichaam2 I follow this approach of having intermediate MutableStateFlow as a uiState in ViewModel. Compose UI uses collectAsState, I see collection happen only when UI is visibile. All the cold flow collections from domain/data are active when viewModel is active and update uiState. I am wondering what level of safety needs to be applied still.
@hichaam2
@hichaam2 2 года назад
@@arunjoseph662 to avoid this you have two options: 1. I wrote an article about the first one, which allows making the long-running Flows lifecycle aware, and stop them when the screen is inactive, google this "Making cold Flows lifecycle-aware" 2. Don't use intermediate MutableStateFlows, and instead compose the upstream Flows and use a `stateIn` operator, like what the video suggests, just be aware that this will cause the whole chain to be restarted each time the screen becomes active again.
@streettrialsandstuff
@streettrialsandstuff 2 года назад
Why do we need this alternative if we already have RxJava? You might as well have added lifecycle helpers for subscribing on lifecycle and that would pretty much be it
@sureshmiyani722
@sureshmiyani722 2 года назад
you can do what you want!
@iandamping9757
@iandamping9757 2 года назад
Great Video!
@jeckonly5853
@jeckonly5853 2 года назад
nice example!! You the handsome guy really help me a lot
@yanxu6184
@yanxu6184 2 года назад
Cool,Thanks!Where are there flow for excample code?
@AndroidDevelopers
@AndroidDevelopers Год назад
Sure! You can check out our samples: goo.gle/3A5BvtJ or the new Now In Android app: goo.gle/3SxsIHU 😎
@witoldsienski1709
@witoldsienski1709 2 года назад
Finally an alternative to rx java :)
@gorkemozgur6796
@gorkemozgur6796 2 года назад
There is also a function called "launchWhenCreated". İsn't that same with "repeatOnLifecycle" ?
@shaiquekhan1185
@shaiquekhan1185 Год назад
it's very different. launchWhen* functions suspend the coroutine while repeatOnLifeCycle cancels and relaunches the coroutine
@johnfriend2010
@johnfriend2010 Год назад
excelente explicacion 👌👌
@souparnodey7382
@souparnodey7382 2 года назад
amazing video
@MicheleFerretti93
@MicheleFerretti93 2 года назад
Thanks for the great content! Will Flows replace the LiveData library entirely? It seems redundant now to have both of them since they do almost the same thing.
@JoseAlcerreca
@JoseAlcerreca 2 года назад
No, LiveData is still a great solution if you want to avoid having to understand everything in the video. It's recommended for beginners and simple cases. And of course, Java users.
@SimoneLeoni
@SimoneLeoni 2 года назад
@@JoseAlcerreca That is a great answer
@Shakesbeer1
@Shakesbeer1 2 года назад
Ok, about this 5 seconds timeout. The most common case you can only imagine - opening details screen from a list screen. Of course one spends more then 5 seconds on the details screen. Then user goes back, and SUDDENLY repository called again, as flow was recreated. How are you going to handle this?
@vinhnguyenuc4282
@vinhnguyenuc4282 2 года назад
Good point, still need another solution for "go back from details screen". Livedata does it well
@kirwakelvinkering3122
@kirwakelvinkering3122 Год назад
The 5 seconds timeout is of no use to me here .for sure it's not efficient to run a loop to fetch data from a server ,what if the data has not changed ? Instead ,we can optimize the messaging services like FCM , and update the mutable state in the viewModel ,then collect this flow as state !
@MegaBezalel
@MegaBezalel 2 года назад
15:41 why would ViewModel recreate the flow if ViewModel is not recreated?
@SimoneLeoni
@SimoneLeoni 2 года назад
Because the activity which is re recreated, calls the collect method
@rinkup2639
@rinkup2639 Год назад
Amazing
@luuvanthao3679
@luuvanthao3679 Год назад
thanks
@user-mu9en3tb8v
@user-mu9en3tb8v 4 месяца назад
cool video)
@technics6215
@technics6215 Год назад
That was really good explanation guys. But all this was about reading data from source, error handling was not covered enough. I wonder how this fits into the real world apps with complicated views, validation etc.
@jonneymendoza
@jonneymendoza Год назад
That's were u use your own imagination and know how's
@technics6215
@technics6215 Год назад
Well I understand that this short video cannot cover everything, but I think they should at least suggest what to watch/read later. Many programmers just follow these naive videos and hit the wall in the real world application
@jonneymendoza
@jonneymendoza Год назад
@@technics6215 that's what seperates the good developers and the average ones. I been on this game for over two decades and made stuff more complex without these new tools. Once you learn that, you can adapt, use these tools and expand on it to meet your needs or just go back to doing stuff before tools like these existed
@heshansandeepa9471
@heshansandeepa9471 9 месяцев назад
awesome
@anmolhira8652
@anmolhira8652 2 года назад
How do i access Android/data folder and add some .bin files in other app directory. please tell me.
@flamyoad
@flamyoad 2 года назад
Need more examples on how to unit test Flows
@chrislagos44
@chrislagos44 2 года назад
I guess is meaningless to use Flow with Firebase real time database since firebase onDataChange method of a ValueEventListener is always listening for updates.
@dev_jeongdaeri
@dev_jeongdaeri 2 года назад
👍👍👍👍👍👍
@pavelgera72
@pavelgera72 Год назад
благодарю
@wanderer_pranab
@wanderer_pranab 2 года назад
Hey, I want to build an app, can you teach me, huch much time it would take?
@ibrahimheroglu
@ibrahimheroglu 9 месяцев назад
9:14 it should be: ".. as called cold flows"
@CanalMateriaGriz
@CanalMateriaGriz 2 года назад
I wish Flutter uses Kotlin. I love Flutter, but Dart sucks compared to Kotlin...
@mahmoudkhairymohamed3572
@mahmoudkhairymohamed3572 Год назад
WOW
@AndroidDevelopers
@AndroidDevelopers Год назад
Hello Mahmoud! If you'd like to learn more, please check out this Kotlin playlist: goo.gle/MAD-Kotlin
@Ihavetoreturnsomevideotapes
@Ihavetoreturnsomevideotapes 2 года назад
Why are you guys slowly trying to kill java
@romank5887
@romank5887 2 года назад
Cause it's old, it sucks and it needs to go away? Or maybe cause Oracle is too greedy?
@siddharthsharma9829
@siddharthsharma9829 2 года назад
"Pencho" - Virat kohli
@ciarz3r
@ciarz3r 10 месяцев назад
This is very advanced stuff for me. Real hard to understand. :(
@nbits7433
@nbits7433 9 месяцев назад
Poor presentation.
@MrJoeycrackers
@MrJoeycrackers 2 года назад
The portion describing repeatOnLifecycle comparatively to lifecyclescope.launch() and lifecycleScope.launchWhenStarrted() is very confusing. The issues are not fully explained IMO and the recommended approach is to use the repeatOnLifecycle to avoid issues. What are the advantages of the other two and why are those advantages not explained in depth here? Or why have they even been added or deprecated?
@mehdiparsaei1867
@mehdiparsaei1867 2 года назад
Thanks for sharing! Please add a "{" after " repeatOnLifecycle(Lifecycle.State.STARTED)"
Далее
What's new in Google Play
10:55
Просмотров 1,5 млн
Kotlin Coroutines 101 - Android Conference Talks
24:49
Просмотров 133 тыс.
МАРИЯ ГОЛУБКИНА О БАБУШКЕ #shorts
00:43
The ABC of Coroutines - Kotlin Vocabulary
9:27
Просмотров 49 тыс.
Kotlin Flows in a Nutshell
13:59
Просмотров 58 тыс.
Здесь упор в процессор
18:02
Просмотров 384 тыс.