-
Notifications
You must be signed in to change notification settings - Fork 51
LocalBroadcastManager will be deprecated from v1.1 #12
Comments
I was using LBM for years as a part of downloader for Google Play Services... now I see it's not available and all I can find is the notice:
Any tip how to replace it in this exact case? |
For this sample, I didn't want the added complexity of saving location data to a database. I just wanted to show how to request and get the location data. That's a good point though on the LBM, so I will add a DataStore (replacement for SharedPreferences) and read data via a Flow when I get the chance. The Flow will emit every time a data changes (codelabs if anyone reads this and is interested). I would go with that method if you don't mind using the alpha, although I was playing with it and it worked pretty well. Otherwise, I usually do a full Room database and observe a LiveData instance to get the data I want. You can see that in the Room with a View codelab, but for this, it would be a little overkill. Either way, thanks for the catch! |
Go for Flow !! BTW: |
@codingjeremy Thank you for this example app! I've been looking at re-architecting several apps that listen for location updates across I wanted to ask you about the best practice for serializing data like Given that both However, the
The counter argument is that this data isn't intended to be long-term storage and as a result the implementation shouldn't change. What are your thoughts on this and the best approach for implementing the (de)serialization of location data for the observable pattern with Room or DataStore when the use case isn't long-term storage? |
I've taken a shot at replacing A summary of the changes are in the README. I'd welcome any feedback from others with more experience for how this can be improved, as it's my first time working with these components! 😃 |
There has not been alot of movement on your quoted fork in the last 12 months. Is your suggested solution to "LocalBroadcastManager" deprecation workable and viable? |
@Hmerman6006 AFAIK yes - I haven't heard otherwise. Here's an article I wrote on the Room + Flow implementation: In my own app I ended up pursuing a lighter-weight approach without Room and using ...and article is here: The 2nd approach without Room and using |
You should rework this example and codelab soon to comply with the changes done here:
https://developer.android.com/jetpack/androidx/releases/localbroadcastmanager#1.1.0-alpha01
Version 1.1.0-alpha01
December 17, 2018
androidx.localbroadcastmanager is being deprecated in version 1.1.0-alpha01.
Reason
LocalBroadcastManager is an application-wide event bus and embraces layer violations in your app; any component may listen to events from any other component.
It inherits unnecessary use-case limitations of system BroadcastManager; developers have to use Intent even though objects live in only one process and never leave it. For this same reason, it doesn’t follow feature-wise BroadcastManager .
These add up to a confusing developer experience.
Replacement
You can replace usage of LocalBroadcastManager with other implementations of the observable pattern. Depending on your use case, suitable options may be LiveData or reactive streams.
RG
The text was updated successfully, but these errors were encountered: