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 change the ListView black top/bottom fade effect color.

Hello all!
Well, I wanted to see if I could change the top/bottom wrap fading
effect seen on most long scrolling components.  In this case I would
like to change the color from black to whatever color I desire on a
ListView.

Is this possible?

Thanks,
Moto!
--~--~---------~--~----~------------~-------~--~----~

2. Perf and usability : How to lazy load an image from the web ?

Here is the code that I have been using, first it will display the
image cached on the android app and then lazy load the other image
from the web but from the de{*filter*}, it does not look like it fully
works...

final ImageView i = new ImageView(mContext);
                    i.setLayoutParams(new GridView.LayoutParams(100,100));
                i.setScaleType(ImageView.ScaleType.CENTER_CROP);
                i.setPadding(8, 8, 8, 8);
                i.setAdjustViewBounds(true);
                i.setImageResource(R.drawable.igift);
                i.post(new Runnable() {
                                        public void run() {
                                                
i.setImageDrawable(util.getDrawable(items.get
(position).getImageUrlForItemDetail()));
                                        }});


//androidUtility class to get the image from an URL
        public Drawable getDrawable(String imgUrl) {
                try {
                        URL url = new URL(imgUrl);
                        InputStream is = (InputStream) url.getContent();
                        Drawable d = Drawable.createFromStream(is, "src");
                        return d;
                } catch (MalformedURLException e) {
                        e.printStackTrace();
                        return null;
                } catch (IOException e) {
                        e.printStackTrace();
                        return null;
                }
        }


thanks !!!

jb
--~--~---------~--~----~------------~-------~--~----~

3. gTalk APIs in 1.0r2

4. How to mute the player when I got an incoming call?

5. Regarding substring function in android

6. How to implement onKeyDown() for KEYCODE_BACK

7. ADC Top 10 Winner Looking for New ADC 2 Teammates