title: The application may be doing too much work on its main thread (Firebase Database) in Andriod
body: <blockquote>
    <p>FRAGMENT CODE</p>
  </blockquote>
  
  <pre><code> ref.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
  
                  list = new ArrayList&lt;&gt;();
                  for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
  
                      for (DataSnapshot dataSnapshot2 : dataSnapshot1.child("Posts").getChildren()) {
  
                          try {
  
                              Model listdata = new Model();
  
                              Model for_post_details = dataSnapshot2.child("info").getValue(Model.class);
  
                              //Toast.makeText(getActivity(), ""+dataSnapshot1.child("username").getValue(), Toast.LENGTH_SHORT).show();
  
                              String path = for_post_details.getPath();
                              String location = for_post_details.getLocation();
                              String caption = for_post_details.getCaption();
                              String username = "" + dataSnapshot1.child("username").getValue();
  
                              listdata.setPath(path);
                              listdata.setLocation(location);
                              listdata.setCaption(caption);
                              listdata.setUsername(username);
  
                              list.add(listdata);
  
                          } catch (Exception ignored) {
                          }
                      }
  
                  }
                  Adapter recyclerview = new Adapter(list, getActivity());
                  RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(getActivity());
                  recycler.setLayoutManager(layoutmanager);
                  recycler.setItemAnimator(new DefaultItemAnimator());
                  recycler.setAdapter(recyclerview);
  
              }
  
              @Override
              public void onCancelled(DatabaseError error) {
              }
          });
  </code></pre>
  
  <blockquote>
    <p>ADAPTER CODE</p>
  </blockquote>
  
  <pre><code>public class Adapter extends RecyclerView.Adapter&lt;Adapter.MyHoder&gt; {
  
      List&lt;Model&gt; list;
      Context context;
  
      public Adapter(List&lt;Model&gt; list, Context context) {
          this.list = list;
          this.context = context;
      }
  
      @Override
      public MyHoder onCreateViewHolder(ViewGroup parent, int viewType) {
  
          View view = LayoutInflater.from(context).inflate(R.layout.recycler_trending,parent,false);
          MyHoder myHoder = new MyHoder(view);
          return myHoder;
      }
  
      @Override
      public void onBindViewHolder(MyHoder holder, int position) {
          Model mylist = list.get(position);
          holder.caption.setText(mylist.getCaption());
          holder.location.setText(mylist.getLocation());
          holder.username_top.setText(mylist.getUsername());
          holder.username_bottom.setText(mylist.getUsername());
          Glide.with(context)
                  .load(mylist.getPath())
                  .into(holder.image);
      }
  
      @Override
      public int getItemCount() {
          return list.size();
      }
  
      class MyHoder extends RecyclerView.ViewHolder{
          TextView total_likes, caption, location, username_top, username_bottom;
          ImageView image;
          ImageButton like, share;
  
          public MyHoder(View itemView) {
              super(itemView);
              total_likes = (TextView) itemView.findViewById(R.id.total_likes);
              caption = (TextView) itemView.findViewById(R.id.caption);
              username_top = (TextView) itemView.findViewById(R.id.username_top);
              username_bottom = (TextView) itemView.findViewById(R.id.username_bottom);
              location = (TextView) itemView.findViewById(R.id.location);
              image = (ImageView) itemView.findViewById(R.id.image);
              like = (ImageButton) itemView.findViewById(R.id.like);
              share = (ImageButton) itemView.findViewById(R.id.share);
  
          }
      }
  </code></pre>
  
  <p>This is code which I'm using for building an app like Instagram.</p>
  
  <p>The code is running fine, but UI is slow, scrolling is slow, the app get hangs.</p>
  
  <p>and I got this message.</p>
  
  <blockquote>
    <p>I/Choreographer(1378): Skipped 65 frames!  The application may be
    doing too much work on its main thread.</p>
  </blockquote>
  
  <p>what I'm doing wrong?? </p>
  
  <blockquote>
    <p>and do you know which technique Instagram uses to display posts
    smoothly?</p>
  </blockquote>
  
  <p>Thanks</p>