Bobbie wrote:
> I am trying to do a real-time chat application (where the Android
> user's text shows up real-time in a web interface running in a browser
> on someon'es PC).  Right now I'm having it post the text in a textbox
> using "onKeyUp" and running it in a background thread (using
> "thread.join()" so it doesn't have to finish sending one character
> before it sends the next one - to keep the app from freezing up) and
> that seems to be running very inefficiently.  I am posting the code I
> am using, can someone help me clean it up and/or make it run more
> efficiently?

Your code snippet is useful, but since it is a part of a larger project,
some of my comments may be completely wrong. So, your patience is requested.

1. Do I understand your flow correctly -- you are sending an HTTP POST
after *every keystroke*? After all, onKeyUp() will get called after
every key event handled by this View. That is absolutely going to be slow.

2. Similarly, it would appear you are forking a thread after every
keystroke, which seems aggressive. How about a single background thread,
using a LinkedBlockingQueue or something for communications? When an
event occurs in the UI thread that the background thread should process,
the UI thread posts an event on the queue. The background thread blocks
on the queue and handles events as they arise.

3. Even if you feel that having one background thread per keystroke is
valid, I am not sure you want to join with the background thread. That
ties up the UI thread until the background thread is done, which is not
what you want.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to