I'm making an app and retrieving data for profile like name, age, username, dob, etc., from a firebase database. But, when I open the app and go to the profile page, it takes about 2 to 3 seconds to refresh the text there and then display the data. I want to make that process faster. Is there anyway to do that? And is it possible to store that data within local storage of the app and display it and update that stored data later using internet and data from firebase database? The same principal I wanted to apply to images which load from firebase storage. Those take much longer than the data. Approximately 4 to 5 seconds.
This is what I'm currently using:
mDatabase = FirebaseDatabase.getInstance().getReference().child(current_user);
mDatabase.keepSynced(true);
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String first = dataSnapshot.child("firstname").getValue().toString();
String last = dataSnapshot.child("lastname").getValue().toString();
String friend = dataSnapshot.child("friends").getValue().toString();
String post = dataSnapshot.child("posts").getValue().toString();
String user = dataSnapshot.child("username").getValue().toString();
String db = dataSnapshot.child("age").getValue().toString();
String ag = dataSnapshot.child("dob").getValue().toString();
String bo = dataSnapshot.child("bio").getValue().toString();
String rela = dataSnapshot.child("relationshipstatus").getValue().toString();
firstname.setText(first);
lasttname.setText(last);
username.setText(user);
friends.setText("Friends:"+friend);
posts.setText("Posts:"+post);
dob.setText("DOB:"+db);
age.setText("Age:"+ag);
bio.setText(bo);
relation.setText(rela);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});