[android-developers] EventQueue.peekMessage

2011-07-07 Thread andrei-dmitriev

Hi folks,

why there is no a way to poll or peek the message from the event queue?
I want it to implement the break for the routine running on the UI thread.
private void longRoutine() {
while (flag){
if (queue.peekMessage() != null) {
return;
}
whatever the code is
}
}

Or am I missing something and actually a way exists?

Thanks,
  Andrei

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


Re: [android-developers] EventQueue.peekMessage

2011-07-07 Thread Mark Murphy
On Thu, Jul 7, 2011 at 9:11 AM, andrei-dmitriev
andrei-dmitr...@yandex.ru wrote:
 why there is no a way to poll or peek the message from the event queue?
 I want it to implement the break for the routine running on the UI thread.
 private void longRoutine() {
    while (flag){
        if (queue.peekMessage() != null) {
            return;
        }
 whatever the code is
    }
 }

 Or am I missing something and actually a way exists?

It's called a background thread. All the cool programmers use them.

Why do you think that you need longRoutine() to be on the main
application thread?

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

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


Re: [android-developers] EventQueue.peekMessage

2011-07-07 Thread andrei-dmitriev
The longRoutine is the drawing procedure which may take up to several 
seconds.


Yep, I tried to relay that onto another thread and draw into the 
SurfaceView but the problem I've faced is that
the original view(s) are still repainted with onDraw() thus the content 
(the background thread is rendering all the time) is missing. It's 
called from the deep android internals so I don't believe I trigger it 
somehow - it's

just a reaction on the invalidate().
Well, it is covered with blank rectangle but I can see the actual 
content under that rectangle.
BTW that looks like a thread condition over there as sometimes (very 
rarely) I can see the content for a few moments which then becomes 
covered with background color.


So far I also tried to:
a) setWillNotDraw(true);
b) unset the background color of the view

Interestingly that in a sample application (a SurfaceView in a 
RelativeView) the b) approach does help and since that we don't have 
such a problem there.


So the problem now could be read like this (I'm starting to think there 
is no way to peek events from the queue, right? :) :

How to switch the SurfaceView's onDraw() method off?
Any cluea of what can make it been called also appreciated.

Thanks,
Andrei


07.07.2011 17:18, Mark Murphy пишет:

On Thu, Jul 7, 2011 at 9:11 AM, andrei-dmitriev
andrei-dmitr...@yandex.ru  wrote:

why there is no a way to poll or peek the message from the event queue?
I want it to implement the break for the routine running on the UI thread.
private void longRoutine() {
while (flag){
if (queue.peekMessage() != null) {
return;
}
whatever the code is
}
}

Or am I missing something and actually a way exists?

It's called a background thread. All the cool programmers use them.

Why do you think that you need longRoutine() to be on the main
application thread?



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


Re: [android-developers] EventQueue.peekMessage

2011-07-07 Thread Jeffrey Brown
You can use a Canvas to draw an image into a Bitmap on a background
thread.  Then when that's finished, draw the Bitmap into the View (in
onDraw) on the main thread.

I'd be worried about a drawing function that takes several seconds to
run.  We like to keep drawing well under 16ms in order to ensure a
good framerate and smooth animations.

Jeff.

On Thu, Jul 7, 2011 at 9:53 AM, andrei-dmitriev
andrei-dmitr...@yandex.ru wrote:
 The longRoutine is the drawing procedure which may take up to several
 seconds.

 Yep, I tried to relay that onto another thread and draw into the SurfaceView
 but the problem I've faced is that
 the original view(s) are still repainted with onDraw() thus the content (the
 background thread is rendering all the time) is missing. It's called from
 the deep android internals so I don't believe I trigger it somehow - it's
 just a reaction on the invalidate().
 Well, it is covered with blank rectangle but I can see the actual content
 under that rectangle.
 BTW that looks like a thread condition over there as sometimes (very rarely)
 I can see the content for a few moments which then becomes covered with
 background color.

 So far I also tried to:
 a) setWillNotDraw(true);
 b) unset the background color of the view

 Interestingly that in a sample application (a SurfaceView in a RelativeView)
 the b) approach does help and since that we don't have such a problem there.

 So the problem now could be read like this (I'm starting to think there is
 no way to peek events from the queue, right? :) :
 How to switch the SurfaceView's onDraw() method off?
 Any cluea of what can make it been called also appreciated.

 Thanks,
 Andrei


 07.07.2011 17:18, Mark Murphy пишет:

 On Thu, Jul 7, 2011 at 9:11 AM, andrei-dmitriev
 andrei-dmitr...@yandex.ru  wrote:

 why there is no a way to poll or peek the message from the event queue?
 I want it to implement the break for the routine running on the UI
 thread.
 private void longRoutine() {
    while (flag){
        if (queue.peekMessage() != null) {
            return;
        }
 whatever the code is
    }
 }

 Or am I missing something and actually a way exists?

 It's called a background thread. All the cool programmers use them.

 Why do you think that you need longRoutine() to be on the main
 application thread?


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


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