0

Scenario

I have released my app on play store which uses

  1. Firebase Realtime database
  2. Has set setPersistenceEnabled(true) for my each Firebase database.

After tracking crashes for few weeks, I encountered this crash.

After bit research, I came to conclusion that inconsistency in data cached by Firebase Database's data persistence can be the reason for this crash.

So I turned off data persistence by calling FirebaseDatabase.getInstance().setPersistenceEnabled(false); for all my databases.

With above changes in code, I released update for my app on Play Store.

But the users (on the new version with persistence disabled) are still getting the crash.

So my queries are

1) Will the app use persisted data even after turning off persistence?

2) Do the user need to clear the app data which will eliminate the crash? (as inconsistent/corrupted cached data is the reason behind the crash)

below are the gradle dependencies in my app related to firebase database

compile 'com.google.firebase:firebase-database:12.0.1'
compile 'com.firebaseui:firebase-ui-database:3.3.0'

2 Answers2

1

Will Firebase read from cached data if i turned off setPersistenceEnabled?

The answer is no. Once you using the following line of code:

FirebaseDatabase.getInstance().setPersistenceEnabled(false);

It means that you won't be able to query your the database when you are offline. This feature will be disabled. To be more clear, every client that is using a Firebase database and uses setPersistenceEnabled(false) will not maintain it's own internal (local) version of the database.

But, by enabling persistence, any data that the Firebase Realtime database client would sync while online, persists to disk and is available offline, even when the user or operating system restarts the app. This means that your app will work as it would be online by using the local data stored in the cache.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
0

Just in case somebody else might need this information.

By default android & ios apps have offline support enabled but only in-memory to handle intermittent connections. This cache will be lost on app restart.

Calling setPersistenceEnabled(true) will persist write operations queue also to disk(aside from those in-memory) to make them available even on app restarts.

:see

https://firebase.google.com/docs/reference/android/com/google/firebase/database/FirebaseDatabase#setPersistenceEnabled(boolean)

https://firebase.google.com/docs/database/android/offline-capabilities#section-offline-behavior

meofthem
  • 1
  • 1