Keeping program responsive

Put your problem here if it does not fit any of the other categories.

Keeping program responsive

Postby confused » Tue Jan 13, 2009 2:03 am

Hi all,
in my irc app, I'm trying to improve the responsiveness when it has to deal with a lot of data at a single time.

At the moment, once the data is append()-ed to the textview, I post a delayed runnable (100ms delay) back to the UI thread to make it scroll right down to the bottom. Unfortunately, without the runnable being posted, the ScrollView doesn't correctly calculate the amount it should scroll.

This works fine for normal situations and the program is fully responsive. But when, there is a lot of channel activity, the queue of Runnables start to strain the UI thread and it has trouble appending the data as it arrives and occasionally causes an ANR.

My question is, how would I get around this? Without the Runnable, it doesn't scroll correctly but with it, it causes problems. A possible solution could be to detect when there is an influx of data and post the Runnable less often, but I'm not sure how I would detect this.

Any tips?
Junior Developer
Junior Developer
Posts: 16
Joined: Fri Oct 03, 2008 2:30 pm


Postby MrSnowflake » Tue Jan 13, 2009 2:37 pm

You should also run the append on the ui thread. And then you can do both at the same time: first append the text to the textView and in the same runnable, scroll down. With this I am assuming you handle the networking in a different thread.
ie (in thread):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. static String stringToAdd = some string...
  3. mActivity.runOnUiThread(new Runnable() {
  5.   public void run() {
  7.     mActivity.mTextView.append(stringToAdd); // or whatever the method is
  9.     mActivity.mTextView.scrollDown();
  11. });
Parsed in 0.012 seconds, using GeSHi
User avatar
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests