title: Google Maps Lite Mode causes jank in RecyclerView
body: <p>I have a <code>RecyclerView</code> which is a vertical scrolling list of items. Each list item contains a Google Maps V2 MapView in <a href="https://developers.google.com/maps/documentation/android/lite" rel="noreferrer"><strong>Lite Mode</strong></a>. I'm taking advantage of this new feature which returns bitmaps instead of a full-blown map as a replacement to the <code>Google Static Maps API</code>.</p>
  
  <p><a href="http://developer.android.com/reference/com/google/android/gms/maps/MapView.html" rel="noreferrer">MapView</a> requires that you call <code>onCreate()</code>, <code>onResume()</code>, <code>onPause()</code>, <code>onDestroy()</code> etc. from the parent Activity/Fragment's corresponding method. Where is the proper place to call these from the <code>RecyclerView.Adapter</code> and/or <code>RecyclerView.ViewHolder</code>?</p>
  
  <p>How can I clean up recycled MapViews so that memory doesn't leak, while keeping the list jank free?</p>
  
  <p><a href="http://android-developers.blogspot.ca/2014/11/google-play-services-65.html" rel="noreferrer">Google says Lite Mode can be used in lists:</a></p>
  
  <blockquote>
    <p>... ‘lite mode’ map option, ideal for situations where you want to
    provide a number of smaller maps, or a map that is so small that
    meaningful interaction is impractical, such as a thumbnail in a list.</p>
  </blockquote>
  
  <p><strong>ListItem.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"&gt;
  
      &lt;com.google.android.gms.maps.MapView
          android:id="@+id/mapImageView"
          xmlns:map="http://schemas.android.com/apk/res-auto"
          android:layout_width="80dp"
          android:layout_height="100dp"
          map:liteMode="true"
          map:mapType="normal"
          map:cameraZoom="15"/&gt;
  
  &lt;!-- ... --&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>RecyclerView.Adapter and ViewHolder</strong></p>
  
  <pre><code>public class NearbyStopsAdapter extends RecyclerView.Adapter&lt;NearbyStopsAdapter.ViewHolder&gt; {
  
      private final Context mContext;
  
      public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
          MapView map;
  
          public ViewHolder(View view) {
              super(view);
              map = (MapView) view.findViewById(R.id.mapImageView);
              // Should this be created here?
              map.onCreate(null);
              map.onResume();
          }
      }
  
      public NearbyStopsAdapter(Context c) {
          this.mContext = c;
      }
  
      @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
          View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item_nearby_stop, viewGroup, false);
          return new ViewHolder(itemView);
      }
  
      @Override public void onBindViewHolder(ViewHolder holder, int position) {
          //Call Async Map here?
          holder.map.getMapAsync(this);
      }
  
      @Override public void onViewRecycled(ViewHolder holder) {
          // Cleanup MapView here?
  //        if (holder.map != null) {
  //            holder.map.onPause();
  //            holder.map.onDestroy();
  //        }
      }
  
      @Override public void onViewAttachedToWindow(ViewHolder holder) {
          // Setup MapView here?
  //            holder.map.onCreate(null);
  //            holder.map.onResume();
      }
  
      @Override public void onViewDetachedFromWindow(ViewHolder holder) {
          // Cleanup MapView here?
  //        if (holder.map != null) {
  //            holder.map.onPause();
  //            holder.map.onDestroy();
  //        }
      }
  
      // ...
  }
  </code></pre>
  
  <p><strong>Logcat:</strong></p>
  
  <pre><code>I/Google Maps Android API﹕ Google Play services package version: 659943
  W/Google Maps Android API﹕ Map Loaded callback is not supported in Lite Mode
  W/Google Maps Android API﹕ Buildings are not supported in Lite Mode
  W/Google Maps Android API﹕ Indoor is not supported in Lite Mode
  W/Google Maps Android API﹕ Toggling gestures is not supported in Lite Mode
  W/Google Maps Android API﹕ Toggling gestures is not supported in Lite Mode
  W/Google Maps Android API﹕ Toggling gestures is not supported in Lite Mode
  W/Google Maps Android API﹕ Toggling gestures is not supported in Lite Mode
  </code></pre>
  
  <p><strong><em>Update: (Jun 8, 2018)</em></strong> Google has released a code sample for using Lite Maps in a ListView. <a href="https://github.com/googlemaps/android-samples/blob/master/ApiDemos/java/app/src/main/java/com/example/mapdemo/LiteListDemoActivity.java" rel="noreferrer">See here</a></p>