Trying to retrieve data from Firebase database is skipping frames. I am trying to iterate through 2000 data nodes and saving it in my SQLite database. Rest the activity does not do much just a GIF is shown while the data is loading on the screen.
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
loadingKidsData(dataSnapshot, id);
loadingReadingData(dataSnapshot);
updateCurrentUserdata(dataSnapshot, id);
loadingParentsData(dataSnapshot, id);
databaseReference.removeEventListener(this);
gotToNewActivity(isParentSignedUp, id);
};
@Override
public void onCancelled(DatabaseError databaseError) {}
});
I also found this but asynchornously retrieving data still results in skipping of frames. What could be the solution to this.
This is how one of the function looks like:
Integer couponcount = dataSnapshot.child("metadata").child("coupons").child("count").getValue(Integer.class);
if (couponDatabaseHandler.getCouponCount() < couponcount) {
couponDatabaseHandler.deleteTable();
Iterable<DataSnapshot> couponSnapshot = dataSnapshot.child("coupons").getChildren();
for (DataSnapshot snapshot : couponSnapshot) {
String code = snapshot.child("couponCode").getValue(String.class);
Integer used = snapshot.child("couponIsUsed").getValue(Integer.class);
couponDatabaseHandler.addCoupon(new Coupon(snapshot.getKey(), code, used));
}
}
Is there a way I could load the data any place but the UI thread so that the skipping of frames does not occur