title: Android: using multithreading to make UI responsive (archieve smooth scrolling)
body: <p>My activity is to download and display announcements (from announcements web-service). In order to keep UI responsive I do following actions in background threads:</p>
  
  <p>1) upload XML (data are stored in XML), </p>
  
  <p>2) process XML,</p>
  
  <p>3) upload images.</p>
  
  <p>Besides, I change priorities of UI and background threads to keep UI thread responsive:</p>
  
  <p>in main thread:</p>
  
  <pre><code>Thread.currentThread().setPriority(10);
  </code></pre>
  
  <p>in background threads:</p>
  
  <pre><code>Thread.currentThread().setPriority(1);
  </code></pre>
  
  <p>Each announcement is put into a TableRow and each TableRow is put in TableView using handler.
  When user scrolls the TableView and is about to reach the end of the table, new rows are added and HTTP-GET for next announcements is sent (+ parcing (using XPath) + image uploading + filling table rows with content).</p>
  
  <p>My problem:</p>
  
  <p>when uploading and parsing is in process user interface is only partially responsive (there are a number of lags 0.1-0.5sec each when user scrolls TableView).</p>
  
  <p>I want to make absolutely smooth scrolling which doesn't depend on data uploading/processing.</p>
  
  <p>What has been done in a wrong way and what else can be done here?
  For example, if I diminish number of operations in handler, it should improve responsiveness... maybe like that. However, I see no heavy and resource-consuming instructions there.</p>
  
  <hr>
  
  <p>UPDATE</p>
  
  <p>I rewrote my code using ListView instead of TableLayout, since the former is considerably faster (as it turned out, I didn't know that). But I still have spikes when XML processing and ListView scrolling were going simultaneously. I made 2 experiments: </p>
  
  <p>1) I removed all background processes - new rows were added to ListView upon scrolling down, but no data were processed for those rows (so they remained empty) - such variant worked great, no any spike, UI absolutely responsive. </p>
  
  <p>2) 2nd experiment was to remove calls to ListView updates (XML file was processed but data found weren't passed to ListView adapter) - that time I had spikes. So I conclude those spikes are due to background threads and are not due to UI update calls.
  How can background threads slow my app if I make them have lower priority than priority of main one?</p>
  
  <p>Is</p>
  
  <pre><code>Thread.currentThread().setPriority(some_int);
  </code></pre>
  
  <p>a correct way to set thread priority?</p>