views:

59

answers:

1

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

A: 

so I think I figured out the problem. It was the MessageQueu in combination with an OnScrollListener I used in an other location of my code. The onScrollListener was called multiple times and so the MessageQueu was blocked with messages from this listener.

fugu2.0