So I was working on a project, something like social network and I came across the problem.
I have finished loading the list of data with Firebase UI component RecyclerView Adapter, it worked. For this I was using the docs, since I am new to Firebase. But every time someone adds a new post the database automatically refreshes itself and goes back to top.
Any idea if I could make the firebase adapter to notify me when the data changes? I am not so good with the adapter so I decided not to use custom, but to use already made adapter.
I am using Kotlin language.
Thank You!!
Related
I want to refresh my list instantly when my datbase get changed but I dont want use firibase database I am using mysql database right now. plese let me know how can i do this
Todo this kind of live data refresh,
normally i suggest and use LiveData Android jetpack feature
Use this
https://developer.android.com/topic/libraries/architecture/livedata
https://www.journaldev.com/21168/android-livedata
I suggest to use a library using Devart
This library shows how to track changes within several commands. Please see link below.
https://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.MySqlDependency.html
I'm using Android Jetpack's new Paging library to display a list of items received from the API.
I want the data on the current page(say page 3) to be refreshed every few minutes without refreshing the whole list with invalidate() function, as this is taking the Recycler view to its first page.
The problem I see here is the Paging library assumes the data is immutable.
https://developer.android.com/reference/android/arch/paging/DataSource#updating-paged-data
On googling, I can see the workaround is to use Room and display the UI based on DB updates from the API call.
Is there any other suggestions to solve this without using a local store.
The only way to get rid of this issue is to introduce a persistence layer with Room. https://github.com/googlesamples/android-architecture-components/tree/master/PagingWithNetworkSample#paging-with-database-and-network
As per docs here : https://developer.android.com/reference/androidx/paging/DataSource#updating-paged-data
If you have more granular update signals, such as a network API
signaling an update to a single item in the list, it's recommended to
load data from network into memory. Then present that data to the
PagedList via a DataSource that wraps an in-memory snapshot. Each time
the in-memory copy changes, invalidate the previous DataSource, and a
new one wrapping the new state of the snapshot can be created.
https://developer.android.com/topic/libraries/architecture/paging/data#consider-content-updates
As you construct observable PagedList objects, consider how content
updates work. If you're loading data directly from a Room database
updates get pushed to your app's UI automatically.
I'm implementing the repository pattern to my project in Android but my main problem is how to control the data the users remove from the web.
Let's take the Github Browser Sample example.
Possibles solutions:
Remove all the Repos and insert the new list everytime I fetch for that user.
Remove all the Repos and insert the new list everytime I fetch for that user if the last fetch was 3 min or more ago
Remove all the Repos table when the app start (so it will show the
real data when the app close and open again).
Implement something like force update (Swipe and refresh) and remove all the Repos and insert them again.
What do you think about how to solve this problem?
Cheers!!
"Remove all the Repos and insert the new list everytime I fetch for that user."
This is a good approach as you still can have something to show to the user while waiting for the api call to complete.
I'm currently doing this in an app I'm working on at the moment using Room database and observing it using LiveData which makes managing the dataset almost trivial.
I have a RecyclerView which loads data from the database using CursorLoader, CursorAdapter, ContentProvider and all that stuff. It is properly showing the data. But what I want is a search functionality where user types and the RecyclerView's data changes accordingly. I have done it before but with CursorLoader I'm not able to do.
I'm thinking of firing another Loader with different Id? Is it a good idea?
Here's the GitHub link of my project.
I started working on a news android app and thought of using firebase to disseminate latest news to my blog readers. So after playing with firebase for couple of days i was able to create database for my app.
Having done that, i thought of adding SwipeRefresh feature to my app so users can swipe to get latest news posted in my database.
But it occurred to me that since firebase database is realtime as we all know, is it necessary to add the swipe to refresh feature when i could just update and deliver news content to my blog readers on the fly?
Thanks.
The Firebase database is a Realtime Database that updates your RecyclerView/Listview, or any view automatically whenever there is a change.
However, don't forget, when you add a single ValueEventListener by database.addListenerForSingleValueEvent();, the method will only be called once EVEN WHEN UPDATED. If you don't want that, you use the method database.addValueEventListener().
Note that you can't yet implement "Swipe-to-refresh" to a FirebaseRecyclerAdapter /FirebaseListAdapter, for that requires you to disable the auto-sync feature, which isn't directly possible.