Android-Firebase Offline Best Practices


Chandra Sekhar

I've been understanding the concept of taking Firebase App offline. According to the documentation, we need to call:

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

But where should we call it? Should it be used in every activity of the application? Because, when I use this method in onCreate() method of Application class, my application crashes continuously.

So the best practice we should follow is to take our app offline.

Another doubt is the difference between the above twoDatabaseReference.keppSynced(true);

Chris Conway

setPersistenceEnabled()Should be called once at startup, before retrieving the first reference to the database. call me directly after i callFIRApp.configure()

Enable persistence to retain information completely offline. An important part of this is that offline requests and updates will complete even if you force close and reopen the app. If you're looking for offline access, you need to set a boolean.

You can use Keep Sync if you want to cache the latest data each time you retrieve information, but don't necessarily need to restore that data the next time you open the app.

A good example of use is if you have a view that accesses details of logged in users. Instead of having to use user details listeners on all views that use these details, you can just specify to keep that database reference in sync and get the latest data faster.

More details about persistence and sync can be read in the Firebase documentation : https://firebase.google.com/docs/database/android/offline-capabilities

Related


Offline Authentication Best Practices in Xamarin

Nestor I am planning to create a Xamarin(.Forms) application which must have authentication: user should provide username and password to get data. The problem is that it also has to work offline (meaning it shouldn't rely on the server for the authentication

Offline Authentication Best Practices in Xamarin

Nestor I am planning to create a Xamarin(.Forms) application which must have authentication: user should provide username and password to get data. The problem is that it also has to work offline (meaning it shouldn't rely on the server for the authentication

Best Practices for Offline Tools with Databases

username During my internship I had to write a tool which should basically have filtering and searching options for the database (sometimes I have to update - maybe in csv format) and should work both offline and online. I was originally thinking of creating a

Offline Authentication Best Practices in Xamarin

Nestor I am planning to create a Xamarin(.Forms) application which must have authentication: user should provide username and password to get data. The problem is that it also has to work offline (meaning it shouldn't rely on the server for the authentication

Offline Authentication Best Practices in Xamarin

Nestor I am planning to create a Xamarin(.Forms) application which must have authentication: user should provide username and password to get data. The problem is that it also has to work offline (meaning it shouldn't rely on the server for the authentication

Best Practices for Offline Tools with Databases

username During my internship I had to write a tool which should basically have filtering and searching options for the database (sometimes I have to update - maybe in csv format) and should work both offline and online. I was originally thinking of creating a

Best Practices for Offline Tools with Databases

username During my internship I had to write a tool which should basically have filtering and searching options for the database (sometimes I have to update - maybe in csv format) and should work both offline and online. I was originally thinking of creating a

Offline Authentication Best Practices in Xamarin

Nestor I am planning to create a Xamarin(.Forms) application which must have authentication: user should provide username and password to get data. The problem is that it also has to work offline (meaning it shouldn't rely on the server for the authentication

Best practices for detecting offline status in service workers

Mining Diver: I have a service worker that should cache the page displayed offline.htmlif the client has no network connection . However, sometimes it thinks the navigator is offline even when it's not there. That is, navigator.onLine === false. This means tha

Best practices for detecting offline status in service workers

Mining Diver: I have a service worker that should cache the page displayed offline.htmlif the client has no network connection . However, sometimes it thinks the navigator is offline even when it's not there. That is, navigator.onLine === false. This means tha

Android Best Practices AsyncTask

Fyodor Dostoevsky I am new to Android development. Sorry for a stupid question. I need to check several http resources (resource1, resource2, etc.) and check if they are up. If resource 1 is not available, the app needs to check if the internet is on (perhaps

Android Permissions - Best Practices

Encoder I have two android apps, a permission provider and a requester. The provider has the following manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.permissionprovider"

Android coding best practices

jazz I'd like to see community input on Android naming best practices: ID name in xml: <TextView android:id="@+id/addressId" /> Would it be better to name the ID "addressId" or "address", or maybe name it "addressTextView"? Variable naming: TextView addre

Android Permissions - Best Practices

Encoder I have two android apps, a permission provider and a requester. The provider has the following manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.permissionprovider"

Android coding best practices

jazz I'd like to see community input on Android naming best practices: ID name in xml: <TextView android:id="@+id/addressId" /> Would it be better to name the ID "addressId" or "address", or maybe name it "addressTextView"? Variable naming: TextView addre

Firebase Targeting Best Practices for EU

Shaheen Ganardine Current settings for my application: BQ: United States Data Flow: United States Cloud Storage: United States VM on compute engine for light cronjobs: US Firebase Project: United States United States Fire Department Most of the traffic to the

Best practices for Kendo UI and Firebase

Tim Are there any recommendations/best practices for integrating Firebase.js with Kendo UI? Angular.js seems to work well with Firebase, but I don't know how to make Kendo's MVVM work so elegantly. John Bristowe I took a shot at it. Please check kendo-fire .

Firebase Targeting Best Practices for EU

Shaheen Ganardine Current settings for my application: BQ: United States Data Flow: United States Cloud Storage: United States VM on compute engine for light cronjobs: US Firebase Project: United States United States Fire Department Most of the traffic to the

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Firebase Android offline performance

Nils When storing around 5000 child nodes under a single node, Firebase is very slow to initialize when using the offline feature. It takes about 30 seconds to execute the first query. Once initialized, executing subsequent queries (such as listing the top 25

Android exception handling best practices?

lady: If my app crashes, it hangs for a few seconds and then Android tells me the app crashed and needs to be closed. So I was thinking of catching all exceptions in the application in a generic way: try { // ... } catch(Exception e) { // ... } And

Best practices for Android MVVM startActivity

Felipe Kenzi Ziba: I am building an Android application using MVVM and DataBinding. I have a function inside my ViewModel that starts an Activity. Is it ok to make onClick call inside ViewModel? like this. public class MyViewModel { public void onClick(Vie

What are the best practices for SQLite on Android?

Vidal Westnes What is the best practice when executing a query on a SQLite database in an Android application? Is it safe to run insert, delete and select queries from AsyncTask's doInBackground? Or should I use the UI thread? I guess database queries might be