title: Retrieving data in android from Firebase is skipping frames
body: <p>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. </p>
  
  <pre><code>  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) {}
      });
  </code></pre>
  
  <p>I also found <a href="https://stackoverflow.com/questions/33723139/wait-firebase-async-retrive-data-in-android/40099900#40099900">this</a> but asynchornously retrieving data still results in skipping of frames. What could be the solution to this.</p>
  
  <p>This is how one of the function looks like:</p>
  
  <pre><code>    Integer couponcount = dataSnapshot.child("metadata").child("coupons").child("count").getValue(Integer.class);
  
      if (couponDatabaseHandler.getCouponCount() &lt; couponcount) {
          couponDatabaseHandler.deleteTable();
          Iterable&lt;DataSnapshot&gt; 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));
          }
      }
  </code></pre>
  
  <p>Is there a way I could load the data any place but the UI thread so that the skipping of frames does not occur</p>