title: Activity implementing Runnable posts to Looper many times
body: <p>I have implemented an application in Android. There are three components: MainActivity, MyWorker and PublishService. MyWorker takes sensor's data from Android's SensorManager then broadcasts to MainActivity. When MainActivity obtains message, It will call a publish function in order to push it to my PublishService. Please see following diagram:
  <img src="https://i.stack.imgur.com/cy3j6.jpg" alt="enter image description here"></p>
  
  <p>Below I have shown the demonstration of my code: </p>
  
  <pre><code>public class MyActivity extends Activity implements  Runnable {
    public class PushReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent i){
        Result = i.getStringExtra("Result");
        Log.d("onReceive_72", Result);
        mSend();
      }
    }
  
    private void  mSend(){
      Log.d("mSend_80","sent");
      handler.post(this);
    }
  
    @Override
    public void run() {
      Log.d("run_87", Result);
      handler.postDelayed(this, 500);
      Publish(Result); // publish function 
    }
  
    // more code here &lt;---&gt;
  
  }
  </code></pre>
  
  <p>My problem is when application runs, the Logcat shows <code>"run_87": Result</code> many times but <code>"onReceive_72": Result</code> and <code>"mSend_80":"sent"</code> appear just once. For instance: </p>
  
  <pre><code>05-11 11:42:01.286  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:01.286  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:01.286  11631-11631/example I/run_87﹕ Result
  05-11 11:42:01.786  11631-11631/example I/run_87﹕ Result
  05-11 11:42:01.946  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:01.946  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:01.946  11631-11631/example I/run_87﹕ Result
  05-11 11:42:02.286  11631-11631/example I/run_87﹕ Result
  05-11 11:42:02.446  11631-11631/example I/run_87﹕ Result
  05-11 11:42:02.556  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:02.556  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:02.556  11631-11631/example I/run_87﹕ Result
  05-11 11:42:02.786  11631-11631/example I/run_87﹕ Result
  05-11 11:42:02.946  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.056  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.221  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:03.221  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:03.221  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.286  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.461  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.556  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.721  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.786  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.836  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:03.836  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:03.836  11631-11631/example I/run_87﹕ Result
  05-11 11:42:03.961  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.056  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.221  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.286  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.336  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.461  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.486  11631-11631/example I/onReceive_72﹕ Result
  05-11 11:42:04.486  11631-11631/example I/mSend_80﹕ sent
  05-11 11:42:04.486  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.556  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.721  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.786  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.836  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.961  11631-11631/example I/run_87﹕ Result
  05-11 11:42:04.986  11631-11631/example I/run_87﹕ Result
  05-11 11:42:05.056  11631-11631/example I/run_87﹕ Result
  </code></pre>
  
  <p>As you can see, for each circle, it starts with <code>onReceive_72</code> and <code>mSend_80</code> and then produces <code>run_87</code>. <code>run_87</code> appears much than its expectation. And next time, <code>run_87</code> tends to produce more than this time. I don't have any idea why this happnes? At once, I think that happens due to Runnable but I do not know how to solve. Could you please give me proper advice, thank you in advance.</p>