title: How to Get GPS Location Using AsyncTask?
body: <p>I have seen many answers for this type of question but its not related with my task. I am trying to get gps location in background but i got exception as <code>Cant Create Handler Inside Thread That Has Not Called Looper Prepare in Android</code> in <code>mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);</code>.</p>
  
  <pre><code>public class GPSLocation extends AsyncTask&lt;Void, Void, Void&gt;
      {  
          @Override
          protected void onPreExecute()
          {  
              super.onPreExecute(); 
              progressDialog = new ProgressDialog(RoadMaintenanceActivity.this);
              progressDialog.setCancelable(true);
              progressDialog.setMessage("Getting GPS Location...");
              progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
              progressDialog.setProgress(1);
              progressDialog.show();
  
          } 
          @Override 
          protected void onProgressUpdate(Void... values) {
              super.onProgressUpdate(values);
              // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
           }
  
          @Override 
          protected void onPostExecute(Void result)
          { 
  
                  progressDialog.cancel(); 
          }
          @Override
          protected Void doInBackground(Void... params) { 
  
              boolean isGps = false;
  
              while(!isGps)
              { 
                  LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
                  LocationListener mlocListener = new MyLocationListener();  
                  mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);   
                  if(longitude !=0 &amp;&amp; latitude!=0)
                  {
                      isGps = true; 
                      sendSMS();
                  }  
              } 
  
              return null;  
  
  
          }
  
       } 
  </code></pre>
  
  <p>I am not sure why we cant call that inside the doBackground() method.</p>
  
  <p>Thanks for your help guys.</p>