Thread loses Message after wait() and notify()

Posted by fugu2.0 on Stack Overflow See other posts from Stack Overflow or by fugu2.0
Published on 2010-04-19T09:49:30Z Indexed on 2010/04/19 9:53 UTC
Read the original article Hit count: 258

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

© Stack Overflow or respective owner

Related posts about android

Related posts about multithreading