WhiskThimble
WhiskThimble

Reputation: 597

SendToTarget GetTarget in BlueTooth Android Chat Sample

I am working on making the BlueTooth Chat Sample working with a remote service instead of a local service (for later use).

But when I try to use the Handler, which is used to display both sent and received messages, an error occurs, which I don't know how to fix :

mHandler.obtainMessage(RemoteServiceClient.MESSAGE_WRITE, -1, -1, buffer).sendToTarget();

This line sends to the Handler some informations, including the message code (MESSAGE_WRITE) and the content of the buffer (buffer) which I would like to display.

But when I send a message in the application, it crashes and the log shows a nullPointerException, which, I guess, corresponds to the lack of getTarget.

My problem is : in the original sample, there is no getTarget (as in my app), but the sendToTarget works perfectly. How can it be explained and how can I make it work in my application?

Upvotes: 0

Views: 535

Answers (1)

WhiskThimble
WhiskThimble

Reputation: 597

I fixed the issue using dispatchMessage :

messageToMainService.what = VALUES_FROM_THREAD;
messageData.putParcelable("pgnParcelable", pgnListParcelable);
messageData.putParcelable("currentLocation", myLocation);
messageData.putLong("timerBoucle", ellapseTime + timeToSleep);
    //messageData.putWhateverYouWant
messageToMainService.setData(messageData);
mHandler.dispatchMessage(messageToMainService);

I wonder if this use is correct. Please tell me if it's not

Upvotes: 2

Related Questions