Thanks for your reply Dianne.

After googling a bit more around your suggestions, I came across wait
() and notify() (methods I completely forgot about!). I've used an
object shared by both threads and used synchronization along with wait
and notify to throttle the sending. It's helped a lot and the UI stays
responsive now.

Thanks again.

On May 18, 3:15 am, Dianne Hackborn <[email protected]> wrote:
> Correct it wouldn't work, since there is a lot of careful dispatching code
> in the window manager that this sleep trick is actually relying on.
>
> There are many ways you can perform throttling, depending on your exact
> situation.  For example:
>
> 1. Put a delay before you send a message, so if you get more information
> from the server during that time it can be batched together.
> 2. Watch for situations where you are generating many messages within a
> certain amount of time, and start batching/delaying when in that situation.
> 3. Have some mechanism to find out when the app is done processing a
> message, and don't send the next message until that occurs (batching
> activity from the server during that time).  (Fwiw, this is basically what
> the window manager does for dispatching events to applications.)
>
>
>
> On Sun, May 17, 2009 at 5:47 PM, al capwn <[email protected]> wrote:
> > My app makes use of threads and uses handlers to send messages to the gui.
> > The thread maintain a connection to a server and receive messages from it.
>
> > The problem I'm having is that sometimes messages arrive really fast, and
> > although the app doesn't anr, the UI freezes as it tries to cope with the
> > fast influx of messages in the queue.
>
> > The rate at which messages arrive from the server is beyond my control, but
> > I need to find a way to throttle to make sure the UI stays responsive. I've
> > read about people having issues in games where touch events have a negative
> > effect on fps and they've used thread.sleep to throttle. Although similar to
> > my issue, I don't think it would work for me because both the UI and
> > background threads as just as important here.
>
> > Does anyone have any other ideas for solving this? Thanks.
>
> --
> 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, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.
--~--~---------~--~----~------------~-------~--~----~
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