Handle One-Time Events with Kotlin's Channels - Android Studio Tutorial

Handle One-Time Events with Kotlin's Channels - Android Studio Tutorial

Philipp Lackner

3 года назад

20,846 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Gabriele Rugani
Gabriele Rugani - 10.08.2023 19:38

Hi, what happen if an event is emitted when the app is in background ?

Ответить
MATTEO
MATTEO - 28.07.2023 21:04

Is there a way to cancel all events in the queue of a Channel?

Ответить
Ahmed Gamal Yousef
Ahmed Gamal Yousef - 23.12.2022 18:53

Hello @Philipp, I have watched a video for you explaining sharedFlow and I think its usage/emission looks like Channel.
If you can just clarify that :) ?

Ответить
Learner
Learner - 21.10.2022 11:09

You are the best.

Ответить
Chris Athanas
Chris Athanas - 04.09.2022 16:17

Why not used shared flow instead of channels?

Ответить
Анастасия Азарьева
Анастасия Азарьева - 12.08.2022 22:01

Thank you so much for your videos!🙂

Ответить
Tanvir Ahmed
Tanvir Ahmed - 04.08.2022 13:39

If i collect data through flow i can emit data wtih flow what is the benefit of channel?

Ответить
George Machibya
George Machibya - 23.06.2022 17:57

Be blessed brother, your video are clean and crystal clear which simplify the hell life of a developer. am a huge fan.

Ответить
SomeBody
SomeBody - 13.06.2022 11:34

channel causes problem when using it in fragment + viewPager

Ответить
Naman Khanna
Naman Khanna - 01.06.2022 10:48

Great content, you are a guide book for android developers

Ответить
jknair
jknair - 14.05.2022 19:53

do we have to close the channel in viewmodel?

Ответить
DXter123
DXter123 - 02.04.2022 12:29

can you please do this video again, but using compose?

Ответить
Richy Rojas
Richy Rojas - 05.01.2022 02:08

You explain very clear.

Ответить
hArsh
hArsh - 24.12.2021 11:08

What are the benefits of using Channels over Sharedflow?

Ответить
Pavel Gordey
Pavel Gordey - 20.10.2021 16:43

Cool man, i love you videos!)

Ответить
J. almadhaji
J. almadhaji - 12.10.2021 01:54

thank you philipp

Ответить
Carson H
Carson H - 07.10.2021 15:49

Compared to LiveData this gives slightly different behaviour right? The event isn't guaranteed to be handled once if the LifeCycleOwner isn't in the right state. Eg if the error arrives before onStart, the event will be lost. Do you think that is ever a problem?

Ответить
Владислав Старіков
Владислав Старіков - 04.08.2021 21:55

What if event was posted before View started collecting flow? Eg event was posted in init {} of ViewModel. In my case, that event was ignored. Upd: The solution is to set buffer size to UNLIMITED . Without that `send` will be suspended and `trySend` will be ignored until flow will be consumed.

Ответить
Hamed Hardani
Hamed Hardani - 29.05.2021 17:48

When I call a function in the ViewModel from a DialogFragment class, and the function sends an event to the main fragment to show a toast it doesn't work. What could be the reason?

Ответить
Kyrylo Prybylskyi
Kyrylo Prybylskyi - 21.04.2021 13:13

It is better to use MutableSharedFlow to same goal rather than Channel, because channels are gonna be used only inside coroutines libraries and won't be available from outside.

Ответить
N's Watching
N's Watching - 06.03.2021 01:26

This is cool. Is there any other use case for channels apart from one time events ?

Ответить
Federico Creti
Federico Creti - 28.02.2021 19:36

What the is the difference between Channels and MutableSharedFlow? Which use in which case?

Ответить
Soothing Life
Soothing Life - 05.02.2021 21:18

I tried without button click , it still shows a snackbar when device is rotated , onclick of button , it works fine as you show but if i directly trigger the code onstart or onCreate without button click , it still shows snackbar one device rotation , any idea why , and thank you for the video , appreciated

Ответить
soulgenn
soulgenn - 25.01.2021 11:28

You could use asLiveData extension to safely observe the flow's data

Ответить
Dummy Dummy
Dummy Dummy - 18.01.2021 21:57

Hey there why don’t you make video on BLE topic it will be good to have a video in your play list😊

Ответить
Rob Gas
Rob Gas - 18.01.2021 14:18

Awesome

Ответить
Юрий Силютин
Юрий Силютин - 18.01.2021 01:32

Extremely clear explanation. Thanks!

Ответить
SpookyNeha
SpookyNeha - 17.01.2021 20:37

Please teach us about Android Profiling too... please

Ответить
Pedro Joya
Pedro Joya - 17.01.2021 15:25

Is this better than using SharedFlow?

Ответить
Muhammed Rishan P
Muhammed Rishan P - 17.01.2021 07:54

Do a in-app purchase tutorial pls

Used to unlock Pro version and when purchesed it removes ads and open premium content

Ответить
Will Goldberg
Will Goldberg - 17.01.2021 04:12

Fantastic tutorials. Thanks!

Ответить
Mustafa Ammar
Mustafa Ammar - 17.01.2021 00:35

very cool video
wish you all the best 👍👍👍

Ответить
Armando Avila
Armando Avila - 16.01.2021 23:57

Thank you, Philipp, I didn't know about Channels 😱

Ответить
Moody mudi
Moody mudi - 16.01.2021 23:38

thank you !

Ответить
Shivam Sethi
Shivam Sethi - 16.01.2021 22:17

Thanks Philip had problems managing 1 time events, did not know of any in-built way

Ответить
Faysal Hossain
Faysal Hossain - 16.01.2021 18:04

please sir make some video with dynamic broadcast receiver and download manager it will be very helpful for every Android developer .


Please 🙏

Ответить
Zeeshan Syed
Zeeshan Syed - 16.01.2021 17:59

😍😍😍

Ответить
Emil Frilund Andersen
Emil Frilund Andersen - 16.01.2021 17:50

Is there any clear advantage to using this over Google's Event wrapper class, in your opinion? Or is it more like just your preferred pattern to use?

Ответить
jayant kumar
jayant kumar - 16.01.2021 17:49

Thank you philipp , i have one question , when you observe flow in main activity , is it lifecycle aware as like Live Data ?

Ответить
Houssem Zaier
Houssem Zaier - 16.01.2021 17:47

You don't have to use the channels. They are complicated and not worth it.

Ответить
Houssem Zaier
Houssem Zaier - 16.01.2021 17:46

Why don't you use the sharedFlow ? It would be even easier

Ответить
Ammar Seud
Ammar Seud - 16.01.2021 17:26

Wait, the Event sealed class is actually a thing? I came up with that on my own like a couple of weeks ago and thought I was a genius lmao. Before that I'd just have a bunch of LiveDatas with different events in every VM XD
It sure is better this way than with the custom Event class though. Thanks for the video! :)

Ответить
Avadhut Tanugade
Avadhut Tanugade - 16.01.2021 17:03

Voice got 🔥

Ответить
s s
s s - 16.01.2021 16:39

last night, i was searching this problem in ur channel and now u hv uploaded this video,, omg amazing 👏 connection

Ответить
Виталий Яковлев
Виталий Яковлев - 16.01.2021 16:26

If need get string for message from resouses, in this case pass context in viewModel?

Ответить
Mohamed Salama
Mohamed Salama - 16.01.2021 16:02

should the event sealed class always be in the viewmodel or if we have a repository we put it in the repository?

Ответить
Chris Athanas
Chris Athanas - 16.01.2021 15:48

Great demo

Ответить
Vishal Thapa
Vishal Thapa - 16.01.2021 15:36

does we have to create both livedata and channel in viewmodel separately based on the events...i.e for single events channel and livedata for the normal behaviour.

Ответить