title: Android Handler doesn't handle messages
body: <p>I'm rather perplexed about this one. I'm taking <a href="https://class.coursera.org/posa-002" rel="nofollow">this Coursera course</a>, and working on <a href="https://github.com/douglascraigschmidt/POSA-14/tree/master/assignments/week-6-assignment-5" rel="nofollow">Assignment 5</a>. I was able to complete the assignment with minimal difficulties, and then proceeded to try and make the code do my own purpose. I made a few tweaks to it as well, but I'm having a significant problem, which I can't for the life of me figure out. The Handler doesn't seem to take messages at all... Any idea what I'm doing wrong?</p>
  
  <p>Here's a few bits of my code. Let me know if there's something else you'd like to see.</p>
  
  <p>Handler:</p>
  
  <pre><code>public class DownloadHandler extends Handler {
  private WeakReference&lt;Context&gt; mContext;
  public DownloadHandler(Context context) {
      super();
      mContext = new WeakReference&lt;Context&gt;(context);
      Log.v(TAG,"Created! "+this);
  }
      // Handle any messages that get sent to this Handler
      @Override
      public void handleMessage(Message msg) {
          Log.v(TAG, "" + msg); //Never reached
                  ...
         }
  }
  </code></pre>
  
  <p>Before I go any further, I've tested the handler by sending a simple message (<code>handler.sendEmptyMessage(0);</code>, with no success. Any ideas?</p>
  
  <pre><code>Log.v(TAG,"handler="+handler);
  Log.v(TAG,"Sending test "+handler.sendEmptyMessage(0));
  </code></pre>
  
  <p>And the logcat:</p>
  
  <pre><code>06-14 22:47:34.700: V/DownloadAddOnProducts(7406): handler=Handler (com.kd7uiy.hamfinder.DownloadHandler) {527724dc}
  06-14 22:47:34.700: V/DownloadAddOnProducts(7406): Sending test true
  </code></pre>
  
  <p>To reduce this even further, I have a unit test:</p>
  
  <pre><code>public class DownloadTester extends InstrumentationTestCase {
      public void setUp() {
          targetContext=getInstrumentation().getTargetContext();
      }
  
      public void testDownloadHandler() {
          Looper.myLooper().setMessageLogging(new LogPrinter(Log.VERBOSE,"DownloadLooper"));
          DownloadHandler handler=new DownloadHandler(targetContext,Looper.myLooper());
          Log.v(TAG,"handler="+handler);
          handler.sendEmptyMessage(0);
          Log.v(TAG,"Send empty message");
      }
  </code></pre>
  
  <p>And the logcat shows:</p>
  
  <pre><code>06-14 23:03:46.068: V/DownloadHandler(8337): Created! Handler (com.kd7uiy.hamfinder.DownloadHandler) {52770be8}
  06-14 23:03:46.068: V/DownloadHandler(8337): Created! Handler (com.kd7uiy.hamfinder.DownloadHandler) {52770f60}
  06-14 23:03:46.068: V/DownloadTester(8337): handler=Handler (com.kd7uiy.hamfinder.DownloadHandler) {52770f60}
  06-14 23:03:46.068: V/DownloadTester(8337): Send empty message
  </code></pre>
  
  <p>It created two DownloadHandlers because the other one is for another unit test in my set of unit tests.</p>