title: How to pass a handler from activity to service
body: <p>How to pass handler from an activity to service? I am trying to update the activity UI on the state of Bluetooth connection by using Handler as shown below from service class. </p>
  
  <pre><code>mHandler.obtainMessage(MenuActivity.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
  </code></pre>
  
  <p>In the activity, I implemented this: </p>
  
  <pre><code>   public void handleMessage(Message msg) {
              switch (msg.what) {
              case MESSAGE_STATE_CHANGE:
                   if (true)
                       Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
                   switch(msg.arg1){
                      case BluetoothService.STATE_CONNECTED:
                          showToast("Connected to " + mConnectedDeviceName, Toast.LENGTH_SHORT);
                          break;
  </code></pre>
  
  <p>I tried to use a constructor to pass the handler from the activity to service like this: </p>
  
  <pre><code>public BluetoothService(Handler handler, BluetoothAdapter mBluetoothAdapter) {
          mAdapter = mBluetoothAdapter;
          mState = STATE_NONE;
          mHandler = handler;
  }
  </code></pre>
  
  <p>But there was an error which shows Unable to instantiate service and found that the service needs to have a public no-args constructor. But after removing the constructor, the handler did not get passed into the service.</p>
  
  <p>How to solve this problem? </p>