Thread loses Message after wait() and notify()
- by fugu2.0
Hey Guys!
I have a problem handling messages in a Thread. My run-method looks like this
public void run() {
Looper.prepareLooper();
parserHandler = new Handler {
public void handleMessage(Message msg) {
Log.i("","id from message: "+msg.getData.getString("id"));
// handle message
this.wait();
}
}
}
I have several Activities sending messages to this thread, like this:
Message parserMessage = new Message();
Bundle data = new Bundle();
data.putString("id", realId);
data.putString("callingClass", "CategoryList");
parserMessage.setData(data);
parserMessage.what = PARSE_CATEGORIES_OR_PRODUCTS;
parserHandler = parser.getParserHandler();
synchronized (parserHandler) {
parserHandler.notify();
Log.i("","message ID: " + parserMessage.getData().getString("id"));
}
parserHandler.sendMessage(parserMessage);
The problem is that the run-method logs "id from message: null" though "message ID" has a value in the Log-statement. Why does the message "lose" it's data when being send to the thread? Has it something to do with the notify? Thanks for your help