Reputation: 923
I am working on Firebase to retreive data using addValueEventListener from Android SDK but i found sometime the response time take minimum 1 minute to get the result.
My Code :
Firebase firebase = new Firebase("https://example.firebaseio.com/");
firebase.child("XYZ").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("DataFirebase","onDataChange : "+dataSnapshot);
Toast.makeText(getApplicationContext(),"onDataChange",Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d("DataFirebase","onCancelled : "+firebaseError);
Toast.makeText(getApplicationContext(),"onCancelled",Toast.LENGTH_SHORT).show();
}
});
This is my above code , please let me know , how can i get the result instantly from a key. Please suggest me some solution.
Upvotes: 3
Views: 2830
Reputation: 2295
I too have a problem of slowness with firebase realtime db. Try calling, FirebaseDatabase.getInstance().setPersistenceEnabled(true);
inside your Application class's "onCreate" method.
Be aware that this will save data on your device and the second call and above will be much faster but from cache and can be outdated, Read this for handling syncing data from server when needed immediately.
Upvotes: 4