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. How to set the 'singleActivityMode' flag for an activity group's constructor?

How can I set the 'singleActivityMode' flag for an activity group's
constructor?

http://code.google.com/android/reference/android/app/ActivityGroup.html#ActivityGroup(boolean)

The problem I am encountering is that although my activity group's
onResume/onPause methods are getting called, the onResume/onPause
methods of each of the activities started by the activity group's
local activity manager are not getting called.  I looked at the source
code for LocalActivityManager's dispatchPause() and dispatchResume()
APIs and I see that when this 'singleActivityMode' flag is
'true' (which is the default), the underlying activities' onPause/
onResume lifecycle events don't get called.
--~--~---------~--~----~------------~-------~--~----~

2. How to set the 'singleActivityMode' flag for an activity group's constructor?

This can't be changed dynamically after the
ActivityGroup/LocalActivityManager is created.






-- 
Dianne Hackborn
Android framework engineer
[EMAIL PROTECTED]

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~

3. Service processing restrictions on main thread

4. What are the possible way to work on database?

5. Radogroup layout question.

6. How do I make sure one row ListView is always in focus

7. How do I make sure one row ListView is always in focus