mehmet
mehmet

Reputation: 1588

Firebase: How to Query Local Database Even if Device is Online

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

How to change behavior of firebase querying for server database or locale database.

DatabaseReference scoresRef = FirebaseDatabase.getInstance().getReference("scores");
scoresRef.keepSynced(false);

Is that possible to make same query for server and than used it from local database. firstly I want to make a query from server database and then without download again and again I want to use same querying datas from local datas even after app is closed.

I am using above codes for using offline firebase and trying to use same datas without download again

Upvotes: 1

Views: 202

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

When you are using the following line of code:

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

It means that Firebase will create a local copy of the database on user device. This means that the application will work even if the device temporarily loses its network connection or if the user restarts the application.

So the answer your question is, that the same query that works when you are online will also work when you are offile, because the database which will be queried is the local database. You don't to do other operations.

Upvotes: 1

Related Questions