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.
Related
I am using Flutter for the app and Django with Postgres for my backend APIs. I want to update the data from API in-app to update in real-time, what is the best way to do it. I went through a lot of blog posts and SO answers and have got the following solutions, Any better solutions would be appreciated
Websockets - difficult to scale
Refresh APIs after every n seconds - Difficult to scale
Firestore in build functions but I don't want to migrate to firebase.
Are there any better solutions? I want the solution to scale to many users so please let me know the best solution for this. Thanks
Update:
I have two data sources, one is the flutter app itself and another is a web dashboard, I want the data in the app which is a listview to get updated whenever new data is added from the dashboard in real-time. The data in the app is a listview that should be updated in real time with new records from the API.
Don't know if this is good solution, but you can try to use FCM from Firebase (you wrote only about firestore/real-time database).
Every time app is in reasumed state it can register token in your backend, and every time web dashboard is being changed, server can send push notification to the app with data/trigger to fetch data.
WebDashboard -> Backend -> FCM(with trigger/ full data) -> Mobile
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 am building an android application and I am facing some weird issues related to FIREBASE DATABASE.
I have created a firebase database and added some tables, fields and added some data, like;
Log in with phone authentications etc.
I can use this database with my android app, but I can't be able to see the database.
I have tried a lot to refresh again and again, but not working.
If someone is using firebase, then please login to the console. firebase and check if you can see it, might be, GOOGLE changes its UI (User Interface).
Help me, please!
It will be a great favor.
I think you are not selecting your project:
Check if that is your project, or change it.
If it's prompting you to create a database for that project, it is because that is not the project you are working on. You need to select the current project you are working on in order to see your database.
There are two options - 1. Realtime Database i.e. Firebase. 2. Cloud FireStore. You have to select 1 instaed of 2. See the image below
I was experiencing the same problem. I was worried that all the data might have been deleted. I just left the tab open and after few minutes the database and its children started showing. I think if your database contains a lot of data, it takes time to load the data.
You have to click on Create Database button and setup rules before you try to save data on database. Remember Your are only setting up rules here not giving any database name.
I have a question of logic with Firebase. The following is:
I have chat, like WhatsApp, when I open the window of a room I instantiate the Firebase and the window is real-time, for that I am using to implement ArrayAdapter the Firebase to recover and gives push the messages, it is ok for me .
My problem is in recent conversation list, it still is still no real-time connection to the firebase because of this my doubt logic:
1- I create an instance of Firebase for each row of my ListView Adapter that implements this screen? I do not know if Firebase see this as a good practice, moreover, I would have to create an instance of array Firebase.
2 - Today I create my own chat Rooms as taking a part of TimeMillis to maintain the uniqueness of the names of Rooms. From that, I change this to also use ArrayAdpter and let Firebase create the unique Chars for these rooms and have a single instance in the same way it works in the Chat window with open Room? The problem I see in this is that once the local Instance of Firebase will hear all the real-time updates of all the beds, including those not belonging to the user in question. This is easy to be treated by checking the room that Firebase is pushing for the client belongs to it or not, but I think that a security breach, do not you think?
If anyone has any better suggestions, please tell me.
The structure today my firebase console for this project:
{
chats
{
Room1 {},
Room2 {},
...
}
}
Firebase already has an official example of a chat application https://github.com/firebase/firechat
If you follow their database structure you can accomplish this functionality quite easily. You can look at it here.
Basically they have room-messages, room-users and users to keep track of users, rooms, and messages. For more questions about how to strucuture data in firebase, see https://firebase.google.com/docs/database/web/structure-data. With this structure you can listen for updates to an individual room.
Per firebase documentation "it's best to keep your data structure as flat as possible."
I am trying to decide on what data storage methods to implement. Here is the situation. Whatever method I choose, it is going to be updated once week (can I update a SQLite db without putting out an update in the market?). The user cannot add or remove items from this ListActivity, they can only pick the ones they want. This data method should be able to remember the selected items during any given week. Let me know what method you would use and why. Thanks so much in advance.
A webservice would allow you to update the data whenever you want without having to push updates to the market. And updating your app in the market doesn't guarantee that users will apply the update. Ofcourse the downside here is that your users would need to be connected to the internet while using the app.
Moving your database to remote server will give you freedom to manipulate data without actual application being updated, thus no need to update on the market. If it is a matter of access to internet, you can still use this practice, just more work has to be done (adding Broadcasters that will listen to connectivity than update the local database with global one on your server, or something similar).
If you want to update the data on the device once a week, then you will need to use the local SQLite database and interact with a web service that provides the updates. You will not need to go through the market to do this. However, if you need to update the structure of the database (add, remove, or change columns or tables for example), then you will need to update your app on the market.
I highly recommend watching the Google IO 2010 talk Developing Android REST client applications. The speaker is the author original author of the Twitter app for Android, and talks about the design patterns and best practices that he uses.