title: How to load Youtube thumbnails in a RecyclerView using Youtube API
body: <p>I'm trying to load Youtube video thumbnails in a RecyclerView. I'm facing some issues.</p>
  
  <p>Here is what I'm doing in my adapter:</p>
  
  <pre><code>public static class ItemViewHolder extends RecyclerView.ViewHolder {
  
      private YouTubeThumbnailView thumb;
      public  Post                 post;
  
      public ItemViewHolder(View v) {
          thumb = (YouTubeThumbnailView) v.findViewById(R.id.youtube_thumbnail);
      }
  
      @Override
      public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
          if (holder instanceof ItemViewHolder) {
  
              ((ItemViewHolder) holder).thumb.initialize(YOUTUPEKEY, new YouTubeThumbnailView.OnInitializedListener() {
                  @Override
                  public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
                      youTubeThumbnailLoader.setVideo(VIDEOID);
  
                  }
  
                  @Override
                  public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
  
                  }});
  }}}
  </code></pre>
  
  <p>It works fine, but I don't I'm doing it right. When I'm using the same adapter in another activity I get this Error:</p>
  
  <pre><code>Activity com.example.yasser.version6.Mespublications has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@4252bcb8 that was originally bound here
  </code></pre>
  
  <p>and it takes time to load thumbnails and sometimes it mix between them when swiping.</p>
  
  <p>I added a function to release all the Youtube Loaders:</p>
  
  <pre><code>public void ReleaseLoaders() {
      for (YouTubeThumbnailLoader loader : loaders.values()) {
          loader.release();
      }
  }
  </code></pre>
  
  <p>and I'm calling this function from the Activity Onstop() :</p>
  
  <pre><code>@Override
  public void onStop() {
      super.onStop();
      mAdapter.ReleaseLoaders();
  }
  </code></pre>
  
  <p>It worked fine for some time, but the crashes sometimes. </p>