It has been a while since i had to do this but i n...
# android
z
It has been a while since i had to do this but i need to pass some data from a forground service back to activity before the service closes. I used to do that using LocalBroadcastManager. Is there a newer way to do that in kotlin? with flows or other types of streams?
stackoverflow 2
o
Nope, the mere existence of Kotlin doesn’t add any new means of communication between Android system components. It’s just a programming language. The kotlin-parcelize plugin is very handy though, so it may help you with sending parcelables with the LocalBroadcastManager
z
Well, this may not be related to kotlin, but if I declare a liveData object, I can use it in the service and observe it in the activity. The question is what are the drawbacks and risks envloved. I can also inject a viewModel with flows and states to the service but again, I am not sure what the risks are in terms of leaks.
o
As for
Flow
, you can of course use `DataStore`/(
SharedPreferences
-based-observable-storage) as the communication medium. I mean if you're feeling particularly naughty you can employ a global
SharedFlow
. Everything depends on the use case.