The main goal of Handler is to provide an interface between the producer and consumer threads, here, between the user interface thread and the workflow. The implementation of Handler goes to the consumer branch.
In your case, you want to communicate MESSAGE_READ between threads.
Without a handler, you cannot do anything from your main theme of activity.
Therefore, look for mHandler initiation in the main activity.
The default init handler should look like this:
Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { } };
If you use Eclipse, click on your project β Ctrl + H β File Search β "Handler".
Or in Notepad ++ β Serch β Find in Files ....
[EDIT]
final int MESSAGE_READ = 9999; // its only identifier to tell to handler what to do with data you passed through. // Handler in DataTransferActivity public Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case SOCKET_CONNECTED: { mBluetoothConnection = (ConnectionThread) msg.obj; if (!mServerMode) mBluetoothConnection.write("this is a message".getBytes()); break; } case DATA_RECEIVED: { data = (String) msg.obj; tv.setText(data); if (mServerMode) mBluetoothConnection.write(data.getBytes()); } case MESSAGE_READ: // your code goes here
I am sure you should implement something like:
new ConnectionThread(mBluetoothSocket, mHandler);
sources i found here
source share