I am currently testing the new firebase on how efficiently we can work with the database offline. For database online offline state we have .info/connected
path to check if database is currently connected or not. And I can change the state with the following code:
mDbStatusRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Boolean connected = snapshot.getValue(Boolean.class);
mDbStatus.setText(String.valueOf(connected).toUpperCase());
if (!connected)
mDbStatus.setTextColor(getResources().getColor(android.R.color.holo_red_light));
else
mDbStatus.setTextColor(getResources().getColor(android.R.color.holo_green_dark));
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Is there any way I can be sure that the database on the local client (cache is what you call) is fully synced or not? Like are there any pending write queues in the cache for the remote?
Or any alternatives/hacks through which I can be sure everything is synced and It is safe to close the connection. It will be useful to sync everytime app starts and close the connection once everything is synced. Or keep the the connection open when there is a need for the realtime syncing and close it once the user is done with it and everything is synced up with the server. And many other use-cases like this.