Ege Kuzubasioglu
Ege Kuzubasioglu

Reputation: 6282

Is it possible to access Firebase realtime database when the device is offline?

I'm developing a native Android application to show rock climbing topos, I receive all the routes and degrees from Firebase's real-time database. However, I thought it would be stupid to require internet all the time since in some places people won't have internet access when climbing.

Now, I'm planning to put a download option so people can store that Firebase data in their devices so they can access them offline.

Is this possible?

I found this:

DatabaseReference gradesRef = FirebaseDatabase.getInstance().getReference("grades");
gradesRef.orderByValue().limitToLast(4).addChildEventListener(new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot snapshot, String previousChild) {
      System.out.println("The " + snapshot.getKey() + " climbing grade is " + snapshot.getValue());
    }
});

to Querying Data Offline but I'm not sure it's the same thing I want to do.

Upvotes: 0

Views: 447

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

Yes it is, using this line of code:

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

This means that you'll have a copy of your data locally and you'll be able to query it and also every change you'll make while you are offiline, will be visible in the database once you are back online.

Hope it helps.

Upvotes: 2

Related Questions