title: Use an Async task for a bitmap
body: <p>I have a method that adds many Markers to a Google Map.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>item = new MapLocation();
  URL myurl = new URL("http://www.canninginc.co.nz/CanFindLocation/yes.png"); 
  Bitmap bmp = BitmapFactory.DecodeStream(myurl.OpenConnection().InputStream);
  item.icon = BitmapDescriptorFactory.FromBitmap(bmp);
  item.Location = new LatLng (-41.227834, 174.812857);
  item.Snippet = "Snippet2";
  item.Title = "Title2";
  item.ShowInfoWindowOnStartup = true;
  _mapLocationList.Add(item);
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <blockquote>
    <p>Exception of type 'Android.OS.NetworkOnMainThreadException' was thrown.</p>
  </blockquote>
  
  <p>I have done some research and I think I need to run the action on another thread when getting the Bitmap.</p>
  
  <p>Can I have some help with this code? Does the AsyncTask return a Bitmap, or how do I tie the two together?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am using Xamarin, and have posted the following code into a new class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Android.App;
  using Android.Content;
  using Android.OS;
  using Android.Runtime;
  using Android.Views;
  using Android.Widget;
  using Android.Graphics;
  
  namespace SimpleMapDemo
  {
      class MyAsyncTask extends AsyncTask&lt;String, Void, Bitmap&gt;
      {
          @Override
          protected Bitmap doInBackground(String... urls) {
              if (urls.length &gt; 0) {
                  URL myurl = new URL("http://www.canninginc.co.nz/CanFindLocation/yes.png"); 
                  return BitmapFactory.DecodeStream(myurl.OpenConnection().InputStream);
              }
  
              return null;
          }
          @Override
          protected void onPostExecute(Bitmap bmp) {
              super.onPostExecute(bmp);
  
              if (bmp != null) {
                  item = new MapLocation();
                  item.icon = BitmapDescriptorFactory.FromBitmap(bmp);
                  item.Location = new LatLng (-41.227834, 174.812857);
                  item.Snippet = "Snippet2";
                  item.Title = "Title2";
                  item.ShowInfoWindowOnStartup = true;
                  _mapLocationList.Add(item);
              }
          }
      }
  }
  </code></pre>
  
  <p>I am getting many errors. Am I placing this code in the correct area?</p>