0
Follow
0
View

Implications of using Flow.asLiveData()

mt0116 注册会员
2023-01-25 06:32

One drawback is that it introduces a platform dependency on Android where you use it (for ex: ViewModels).

But you could instead use StateFlows or SharedFlows and when you consume it you can tie the subscription to the lifecycle, making it lifecycle-aware. So this way the Publisher/Flow isn't lifecycle-aware, but our Observer/Subscriber is.

A good article about this: https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda

About the Author

Question Info

Publish Time
2023-01-25 06:32
Update Time
2023-01-25 06:32