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. Good news: Google started removing spam from the market, (finally).

I was delighted to see that, apparently, Google started doing something 
about the vast number of junk/spam apps in the Android Market, so I thought 
I'd share the good news here.


A Blog post:
http://www.androidguys.com/2010/07/28/spammer-responds-flood-android-market/

Relevant post in the support forum:
http://www.google.com/support/forum/p/Android+Market/thread?tid=112b21331f966357&hl=en

... and this is from one of the offenders, threatening to fight back:
http://www.google.com/support/forum/p/Android+Market/thread?tid=03c17b94b307c47b&hl=en


This has been, so far, the one and only reason that kept me from developing Android apps. Let's hope Google are seriously tackling this problem. -- Marcelo - http://maps.forum.nu -- --

2. Good news: Google started removing spam from the market, (finally). :-)

I was delighted to see that, apparently, Google started doing
something about the vast number of junk/spam apps in the Android
Market, so I thought I'd share the good news here.

A Blog post:
http://www.androidguys.com/2010/07/28/spammer-responds-flood-android-market/

Relevant post in the support forum:
http://www.google.com/support/forum/p/Android+Market/thread?tid=112b21331f966357&hl=en

... and this is from one of the offenders, threatening to fight back:
http://www.google.com/support/forum/p/Android+Market/thread?tid=03c17b94b307c47b&hl=en


This has been, so far, the one and only reason that kept me from
developing Android apps. Let's hope Google are seriously tackling this
problem.

--
Marcelo - http://maps.forum.nu
--

-- 

3. How to close/hide the Android Soft Keyboard?

4. Android Scan

5. Confirmation routine

6. Building Android source on Gentoo

7. Licensing