title: Geolocation request made in background thread freezes the main thread
body: <p>I have the following working flow of my application: main activity has a button which starts the second activity after the click. In the second activity there is a <code>TextView</code> which shows the city which located in the specified geopoint. To find this city I make a request to <a href="http://developer.android.com/reference/android/location/Geocoder.html" rel="nofollow">Geocoder</a> which I make in the background thread. </p>
  
  <p><strong>What I expect:</strong> second activity starts (almost) immediately, when background thread finishes the request, ui thread updates the <code>TextView</code> content.  </p>
  
  <p><strong>What happens:</strong> the second activity gets started <em>only</em> when <code>Geocoder</code> finishes its job. To make it obvious we can turn off the wi-fi and click on the button - five-six seconds of expectation, and right after the message that tells that <code>Geocoder</code> couldn't get the geopoint appears in the log, the second activity launches.</p>
  
  <p>What I'm doing wrong? The relevant code is below, the full sample project is <a href="https://github.com/agap/handlersample" rel="nofollow">on github</a>.</p>
  
  <pre><code>public class SecondActivity extends Activity implements Handler.Callback {
      private HandlerThread mHandlerThread = new HandlerThread("BackgroundThread");
      private Handler mUIHandler;
      private Handler mBackgroundHandler;
  
      private TextView mLocationView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_second);
  
          mLocationView = (TextView) findViewById(R.id.location_name);
  
          mUIHandler = new Handler(getMainLooper(), this);
  
          mHandlerThread.start();
          mBackgroundHandler = new Handler(mHandlerThread.getLooper()) {
              @Override
              public void handleMessage(Message msg) {
                  if (msg.what == 0) {
                      final Geocoder geocoder = new Geocoder(SecondActivity.this);
  
                      try {
                          final List&lt;Address&gt; results = geocoder.getFromLocation(53.539316, 49.396494, 1);
  
                          if (results != null &amp;&amp; !results.isEmpty()) {
                              mUIHandler.dispatchMessage(Message.obtain(mUIHandler, 1, results.get(0)));
                          }
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
              }
          };
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          mBackgroundHandler.dispatchMessage(Message.obtain(mBackgroundHandler, 0));
      }
  
      @Override
      public boolean handleMessage(Message msg) {
          if (msg.what == 1) {
              mLocationView.setText("I live in " + ((Address) msg.obj).getLocality());
              return true;
          }
  
          return false;
      }
  }
  </code></pre>