title: What is the best and quickest way to set up a google map in android?
body: <p>I'm creating an app that will basically allow users to save their location as a crag (rock climbing). I'm saving the info in a database behind a content provider. But the problem is in setting up the Google map I'm using to allow users to set their location. At the moment I'm setting in up when the location provider is connected, using the onConnected() method, this seems to slow the starting of the activity. I tried to speed it up by doing the map stuff in an ASyncTask but this crashes because maps doesn't seem to want to run in another thread. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>package com.fooforever.climbtrack;
  
  import android.app.Activity;
  import android.content.ContentValues;
  import android.location.Location;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.NavUtils;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.CheckBox;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.GooglePlayServicesClient;
  import com.google.android.gms.location.LocationClient;
  import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.MapFragment;
  import com.google.android.gms.maps.model.LatLng;
  
  public class AddCragActivity extends Activity implements
      GooglePlayServicesClient.ConnectionCallbacks,
      GooglePlayServicesClient.OnConnectionFailedListener{
      private GoogleMap map;
      private LocationClient locationClient;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_addcrag);
          locationClient = new LocationClient(this, this, this);
          locationClient.connect();
          setUpMapIfNeeded();
      }
  
      public void onClickSave(View v) {
          CheckBox tradCb = (CheckBox) findViewById(R.id.tradCb);
          CheckBox boulderCb = (CheckBox) findViewById(R.id.boulderCb);
          CheckBox sportCb = (CheckBox) findViewById(R.id.sportCb);
          EditText cragName = (EditText) findViewById(R.id.cragNameEt);
          String name = cragName.getText().toString();
          String type = "";
          if(tradCb.isChecked()) {
              if(type.isEmpty())
                  type = "Trad";
              else
                  type = type.concat(" Trad");
          }
          if(boulderCb.isChecked()) {
              if(type.isEmpty())
                  type = "Bouldering";
              else
                  type = type.concat(" Bouldering");
          }
          if(sportCb.isChecked()) {
              if(type.isEmpty())
                  type = "Sport";
              else
                  type = type.concat(" Sport");
          }
  
          Log.d("ClimbTrack", "type = " + type);
          // check for empty strings
          boolean nisE = name.isEmpty();
          boolean tisE = type.isEmpty();
  
          if(!nisE &amp;&amp; !tisE) {
              // put the info into the database
              ContentValues values = new ContentValues();
              values.put(ClimbProvider.NAME, name);
              values.put(ClimbProvider.TYPE, type);
              Uri uri = getContentResolver().insert(ClimbProvider.CONTENT_URI_CRAGS, values);
              Toast.makeText(getBaseContext(), "Saved successfully" , 
                      Toast.LENGTH_SHORT).show();
              // go back an activity
              NavUtils.navigateUpFromSameTask(this);
          } else if(nisE &amp;&amp; !tisE)
              Toast.makeText(getBaseContext(), "No crag name!" , 
                      Toast.LENGTH_SHORT).show();
          else if(!nisE &amp;&amp; tisE)
              Toast.makeText(getBaseContext(), "No crag type!" , 
                      Toast.LENGTH_SHORT).show();
          else 
              Toast.makeText(getBaseContext(), "No crag name or type!" , 
                      Toast.LENGTH_SHORT).show();
  
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      private void setUpMapIfNeeded() {
          // Do a null check to confirm that we have not already instantiated the map.
          if (map == null) {
              map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                                  .getMap();
              // Check if we were successful in obtaining the map.
              if (map != null) {
                  // The Map is verified. It is now safe to manipulate the map.
  
              }
          }
      }
  
      @Override
      public void onConnectionFailed(ConnectionResult arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onConnected(Bundle arg0) {
          //MapTask mapTask = new MapTask();
          //mapTask.execute();
          map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
          map.getUiSettings().setZoomControlsEnabled(false);
          map.getUiSettings().setMyLocationButtonEnabled(true);
          map.setMyLocationEnabled(true);
          Location currentLocation = locationClient.getLastLocation();
          LatLng currentLatLng = new LatLng(currentLocation.getLatitude()
                  , currentLocation.getLongitude());
          map.moveCamera(CameraUpdateFactory.newLatLng(currentLatLng));
          map.animateCamera(CameraUpdateFactory.zoomTo(15));
  
      }
  
      @Override
      public void onDisconnected() {
          // TODO Auto-generated method stub
  
      }
  
  //  private class MapTask extends AsyncTask&lt;Void, Void, Void&gt; {
  //      @Override
  //      protected Void doInBackground(Void... params) {
  //          map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
  //          map.getUiSettings().setZoomControlsEnabled(false);
  //          map.getUiSettings().setMyLocationButtonEnabled(true);
  //          map.setMyLocationEnabled(true);
  //          Location currentLocation = locationClient.getLastLocation();
  //          LatLng currentLatLng = new LatLng(currentLocation.getLatitude()
  //                  , currentLocation.getLongitude());
  //          map.moveCamera(CameraUpdateFactory.newLatLng(currentLatLng));
  //          map.animateCamera(CameraUpdateFactory.zoomTo(15));
  //          return null;
  //      }}
  }
  </code></pre>
  
  <p>The ASyncTask is commented here but that's how I implemented it.
  Is there any better way than they way I'm doing it without an ASyncTask or a way to do it with one?</p>