Skip to main content

Firebase Database Offline Capabilities | Android Studio | Kotlin

Firebase Offline Capabilities for Firebase Database

What if there is a temporary internet issue with your device? What if you don't want to load your database data again & again? Firebase easily allows you to achieve this task by persisting the data locally, managing presence and handling the latency. The data is available offline even if you restart the app or device. It will behave the same as you're online. Firebase keeps a queue of all write operations that are performed while your application is offline e.g. unstable internet connection. When your app becomes online all the queued write operations are sent to the Firebase Realtime Database Server.

Firebase Database Offline Capabilities | Android Studio | Kotlin

>>Check For Java

Enabling Firebase Offline Persistence

Once you enable the Disk Persistence then the firebase handles the job automatically. You just need to add the following code snippet in your Application Class.

MyApplication.java

class MyApplication : Application() {

override fun onCreate() {
super.onCreate()

////enable firebase offline capabilities
Firebase.database.setPersistenceEnabled(true)

}
}

Keep Required Data Refresh

What if you want to keep some data synced? This is easily possible as you can keep specific locations synced even if the firebase database persistence is enabled. 

val usersRef = Firebase.database.getReference("Users")
usersRef.keepSynced(true)

You can turn the synchronization off later with the following code snippet.

usersRef.keepSynced(false)


Popular posts from this blog

Evolution X Snow 6.3.1 Android 12.1 for Xiaomi Mi Note 10 Lite (toco) - Updated 07/05/22

Evolution X 6.3.1 for the Xiaomi Mi Note 10 Lite [toco]Living, Breaking, Keep Evolving.Evolution X is a flashable custom ROM to bring a true Pixel feel to your Android Device at first glance, with many additional configurations at your disposal. We aim to provide frequent builds with monthly security patches from the latest AOSP sources! - Team Evolution X -Joey Huab (Founder & Lead Developer)

Evolution X Snow 6.5 Omega Android 12.1 for Xiaomi Mi Note 10 Lite (toco) - Updated 13/06/22

Evolution X 6.5 for the Xiaomi Mi Note 10 Lite [toco]Living, Breaking, Keep Evolving.Evolution X is a flashable custom ROM to bring a true Pixel feel to your Android Device at first glance, with many additional configurations at your disposal. We aim to provide frequent builds with monthly security patches from the latest AOSP sources! - Team Evolution X -Joey Huab (Founder & Lead Developer)

Pixel Experience Plus 12.1 for Xiaomi Mi Note 10 Lite (toco) - Updated 20/04/22

 PixelExperience for Xiaomi Mi Note 10 Lite (toco)What is this?Pixel Experience is an AOSP based ROM, with Google apps included and all Pixel goodies (launcher, wallpapers, icons, fonts, bootanimation).In addition to some extra but basic customization.Our mission is to offer the maximum possible stability and security, along with essential and useful features for the proper functioning of the