Aniket Patil Aniket Patil - 2 months ago 35
Android Question

Firebase UI delay in populating View?

I am using firebase UI List adapter but whenever the activity is opened it takes quiet a lot of time like 5-8 seconds before it shows something in list . There is no issue with my network i am not getting where exactly problem is . My code is like this .

I am fetching data inside the fragment like this

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_coming, container, false);

final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.keepSynced(true);
mAuth = FirebaseAuth.getInstance();

comingList =(ListView)view.findViewById(R.id.listViewComing);

FirebaseListAdapter<userData> firebaseListAdapter=new FirebaseListAdapter<userData>(
getActivity(),
userData.class,
R.layout.item_list,
mDatabase.child("coming"))
{

@Override
protected void populateView(View v, userData model, int position) {

ImageView imageView = (ImageView) v.findViewById(R.id.imageViewList);
TextView textView = (TextView) v.findViewById(R.id.textViewList);
textView.setText(model.getName());
Glide.with(imageView.getContext()).load(Uri.parse(model.getImageURI())).into(imageView);

}
};

comingList.setAdapter(firebaseListAdapter);

return view;

}


So basically i need solution for


  1. Fetch data fast

  2. How to implement add progress indicator in fragment for firebaseUI ?


Answer

I solved this by enabling offline cache in Firebase

Firebase.getDefaultConfig().setPersistenceEnabled(true);