title: Adding multiple markers to Google Maps API v2 from List array with the helping of AsyncTask
body: <p>My app requires adding of hundreds markers (in some cases). For this I am using "for loop" which seems to be not bad solution if I am using default markers. I need to use custom image for each marker which I am downloading from the internet with the helping of <code>AsynkTask</code> class <code>Loader()</code>. But when I am using custom markers the UI freezes until "for loop" will be finished.</p>
  
  <p><strong>Adding markers:</strong></p>
  
  <pre><code>private List&lt;User&gt; mUsers = new ArrayList&lt;User&gt;();
  private GoogleMap mMap;
  Bitmap bAvatar;
  
  .............
  
  private void drawMarkers() {
          mMap.clear();
          for (User user : mUsers) {
              if (user.getGeohash() != null) {
                  LatLng pos = gh.decode(user.getGeohash());
                  if (user.getAvatar() != null) {
                      try {
                          bAvatar = new Loader().execute(user.getAvatar()).get();                     
                      } catch (InterruptedException e1) {
                          // TODO Auto-generated catch block
                          e1.printStackTrace();
                      } catch (ExecutionException e1) {
                          // TODO Auto-generated catch block
                          e1.printStackTrace();
                      }
                      mMap.addMarker(new MarkerOptions()
                              .position(pos)
                              .title(user.getStatus())
                              .icon(BitmapDescriptorFactory.fromBitmap(bAvatar)));
                  } else {
                      mMap.addMarker(new MarkerOptions()
                              .position(pos)
                              .title(user.getStatus())
                              .icon(BitmapDescriptorFactory
                                      .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
                  }
  
              }
          }
      }
  </code></pre>
  
  <p><strong>AsyncTask for image downloading:</strong></p>
  
  <pre><code>public class Loader extends AsyncTask&lt;String, Void, Bitmap&gt; {
      Bitmap bitmap;
  
      @Override
      protected void onPreExecute() {
          // TODO Auto-generated method stub
          super.onPreExecute();
      }
  
      protected Bitmap doInBackground(String... urls) {
          String urldisplay = urls[0];
          Bitmap mIcon11 = null;
          try {
              InputStream in = new java.net.URL(urldisplay).openStream();
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inPurgeable = true;
              options.inInputShareable = true;
              mIcon11 = BitmapFactory.decodeStream(in, null, options);
          } catch (Exception e) {
              String error = (e.getMessage() == null) ? "doInBackground - Loader"
                      : e.getMessage();
              Log.e("Error", error);
              e.printStackTrace();
          }
          return mIcon11;
      }
  
      protected void onPostExecute(Bitmap result) {
  
          bitmap = result;
  
      }
  }
  </code></pre>
  
  <p>I assume that I need to replace "for loop" with the <code>AsynkTask</code> where each user from <code>List&lt;User&gt;</code> will be downloaded asynchronously.</p>
  
  <ol>
  <li>Please help me to create <code>AsynkTask</code> for <code>List&lt;User&gt;</code> array.</li>
  <li>Should I combine <code>AsynkTask</code> for <code>List&lt;User&gt;</code> with <code>AsynkTask</code> for image downloading or is it correct to use <code>AsynkTask</code> inside <code>AsynkTask</code> ?</li>
  </ol>
  
  <p>Any help will be appreciated. Thanks in advance.</p>