Hi.
I'd like to know if Looper can enable handler to handle one message at
a time, instead of handling all the messages in the queue together in
one blocking call when Looper.loop() is called.

Because the looper sends all the messages in the queue to the handler
one after the other in one blocking call, my application displays the
ANR message. Instead, I want to be able to handle one single message,
one blocking call at a time - the instant it falls into the queue.

The following code illustrates my problem: (pls note the lines
referred: 1,2,3,4&5)
Question 1: After calling looper.loop in line3, line4 and 5 don't run.
Why is this? I tried quit(), but it doesn't help.
Question 2: Instead of displaying 0,1,2,3,4 in one blocking call (at
line3), I'd like to have 5 different blocking calls for each.
Essentially (sorry, if i sound repetitive), I want to be able to use
looper in such a way that each time, it ensures only one message gets
handled. Is there a way to do this?

I'd appreciate any thoughts on this.
Thanks for the help!!

public class TestLoop extends Activity implements Runnable {
        private Thread bkdg;

        private Handler handler = new Handler() {

                @Override
                public void handleMessage(Message msg) {
1)                      Log.i("Bkdg thread", "Message what = " + msg.what);
                        super.handleMessage(msg);
                }

        };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        bkdg = new Thread(this);
        bkdg.start();

    }

        public void run() {
                Looper.prepare();
                int i = 0;
                while(i < 5) {
2)                      handler.sendEmptyMessage(i);
                        i++;
                }
3)              Looper.loop();
4)              handler.sendEmptyMessage(5);
5)              Log.i("bkdg thread", "reached here");
        }

}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to