Handler loses message after wait() and notify()

by fugu2.0 » Fri, 23 Apr 2010 08:02:06 GMT


Sponsored Links
 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"));
         // further message handling
         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

--



Other Threads

1. Reminder: IRC office hours tomorrow

Just a quick reminder for IRC office hours tomorrow at 9am PST, please
submit your questions at:

http://moderator.appspot.com/#15/e=120951&t=1286cf

thanks,
Megha

2010/1/4 Megha Joshi <mjo...@google.com>





>> > >>

2. tmobile family plan pity party!

Here is a place for me and everyone else who has a tmobile family
plan, and therefore is not eligible to get a subsidized Nexus One.  I
am going to cry myself to sleep tonight, I was really hoping that was
just a rumor I am pretty devastated that its true :(

3. FileWriter cannot create a file in sdcard with Android SDK 1.6

4. Nexus One - Please make available as DEV phone, so non US dev's can buy/support apps

5. Platform Eclair is a preview and requires appication manifests to set minSdkVersion to 'Eclair'

6. Resource not found errors for images referred to in a button image selector xml file

7. List with image items