1

I have a utility class where I attempt to send a message. I also created a custom Handler class to handle the messages response. The problem is that handleMessage(Message msg) is not getting called at all. Is it that I'm understanding something incorrectly?

I've tried playing around with placing the handler in different areas of the app structure but I still don't receive any messages.

Below are the public methods that I use in my utility class to send the message into the queue:

    public boolean sendRequestToService(int what, Bundle data){

        boolean ok = false;
        Message message = new Message();
        message.what = what;

        if(data!=null){
            message.setData(data);
        }

        if (null != mService) {
            try {
                mService.send(message);
                ok = true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
        return ok;
    }

    private void registerToService() {
        try {
            Message msg = Message.obtain(null, 14);

            Messenger mFromService = new Messenger(new MyAppHandler(this));

            msg.replyTo = mFromService;
            if (null != mService) {
                mService.send(msg);
            }

        } catch (RemoteException e) {
        }
    }

/////////////////////////////
//////MyAppHandler.java//////
/////////////////////////////
    public class MyAppHandler extends Handler implements BluetoothAPI {

         private BluetoothDataListener dataListener;

         public MyAppHandler(BluetoothDataListener dataListener){
             super();
             this.dataListener = dataListener;
         }


         @Override
         public void handleMessage(Message msg) {
             System.out.println("handle message");
         }
     }
sfas
  • 185
  • 1
  • 3
  • 17

0 Answers0