I am attempting to pass a message from a Thread to the Handler however, the Handler actions of the handler switch statement are never being processed.
This is my Handler:
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what) {
case SUCCESS:
ConnectedThread connectedThread = new ConnectedThread((BluetoothSocket)msg.obj);
String s = "Successfully Connected";
connectedThread.write(s.getBytes());
break;
case MESSAGE_READ:
byte[] readBuff = (byte[])msg.obj;
String string = new String(readBuff);
Toast.makeText(getApplicationContext(), string, 0).show();
}
}
};
This is the Thread run() method where the message is being passed to the Handler. The Thread is an inner class.
public void run() {
if (D) Log.e(TAG, "-- ConnectThread --");
// Cancel discovery because it will slow down the connection
mBtAdapter.cancelDiscovery();
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
// Do work to manage the connection (in a separate thread)
mHandler.obtainMessage(SUCCESS, mmSocket).sendToTarget();
if (D) Log.e(TAG, "--SUCCESS--");
}
I'm unsure as to why these actions are not being carried out.