Firebase realtime database: How to stop offline write? (Best approach)

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

Currently, in order to prevent write to Firebase after returning back from offline, I check for internet connectivity before every write operation. And by that I do not mean just checking for network connectivity, but also if there is actual internet access available. I ping google.com in order to find out.

I do not think this is the best way to do that.

So, what is the best practice to just tell Firebase not to cache any write operations when there is no internet connection available and just preview a plain simple "No internet connection available" message?

profilepic.png
manpreet 2 years ago

If you really must make your application unusable when the user's device even temporarily loses its connectivity, you will have to add a listener to a special location called /.info/connected. It will tell you when the SDK thinks it has lost its connected. This is described in the documentation. You will have to write code to make your app behave the way you want when your listener is notified like this.

However, your application may have still written data in the time it took from the moment the connection to became stalled, before the SDK makes a decision that the connection is actually gone. And those writes will still be synchronized.

It's better to just make your application usable offline, and notify the user when their data isn't yet synchronized due to being offline.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community