title: Performance issues updating multiple UI elements every second
body: <p><strong>EDIT</strong>: I've posted my solution below, (basically, ListViews are very slow for some reason), and will try to update it further if I can clarify why exactly a ListView is so awful in this situation.</p>
  
  <p><strong>Objective:</strong></p>
  
  <p>Get 7 ListView objects showing 7 independently set clocks/timers which update/tick every second.  These clocks are just Strings with a calculated elapsed time shown (SystemClock.ElapsedRealTime() - stored ElapsedRealTime() of when the object was instantiated.)</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>Basically, 8 minutes into these 7 clocks ticking away - my program is essentially useless.. the information presented is inaccurate, the UI is pretty much unresponsive, etc.  Here are some results of testing against the benchmark of a physical stopwatch:</p>
  
  <ul>
  <li>At 04:00, clocks are slipping 1 second, and updating every 4 seconds.</li>
  <li>At 06:00, clocks are slipping 3 seconds, and updating every 5 seconds.</li>
  <li>At 08:00, clocks are slipping 6-7 seconds, and updating every 6 seconds.</li>
  <li>At 16:00, clocks are slipping 7 seconds, and updating every 10 seconds.</li>
  </ul>
  
  <p><strong>What I have so far:</strong></p>
  
  <p>I have a custom class, ActivityTimer, with a stored long representing the SystemClock.ElapsedRealTime() of when each ActivityTimer was first instantiated.  By clicking on a Button 7 times, I instantiate 7 of these, each of which are added to an ArrayList</p>
  
  <p>I have a compound view, ActivityTimerControl, which is passed an ActivityTimer upon instantiation, and then presents data elements of my ActivityTimer in UI elements (such as the ticking clock.)  My ArrayAdapter handles this instantiation and works fine.  As per <a href="http://developer.android.com/resources/articles/timed-ui-updates.html" rel="nofollow">this fine tutorial</a> I have a _Handler in this ActivityControl, which upon construction of the ActvityControl posts this: </p>
  
  <pre><code>private Runnable _timerUpdateTask = new Runnable() 
  {
      public void run() 
      {
          final long start = _ActivityTimer.getStartTime();
          long millis = SystemClock.elapsedRealtime() - start;
          int seconds = (int) (millis / 1000);
          int minutes = seconds / 60;
          seconds     = seconds % 60;
          if (seconds &lt; 10) 
          {
              _tglActivityPauseButton.setTextOn(""+minutes+":0"+seconds);
          } 
          else 
          {
              _tglActivityPauseButton.setTextOn("" + minutes + ":" + seconds);            
          }
          _tglActivityPauseButton.setChecked(true);
          _timerUpdateHandler.postDelayed(this, 1000);
          }
  };
  </code></pre>
  
  <p>Other than what I've described my project really doesn't do anything yet, as I've been stuck on this fundamental issue so far.  So I haven't posted any other code because I just don't think its relevant beyond the summaries I've given above - but if anyone feels some other part of the project is relevant just let me know and I'll post the detailed code for it.  I'm presenting my final String into the SetTextOn() of a ToggleButton, but testing has shown that this isn't a significant factor - it doesn't matter whether I'm setting the Text of a normal TextView, or what, no matter what I've tried my results are always roughly the same, with noticable lag on each clock and eventually the UI becoming unresponsive completely.  </p>
  
  <p>My understanding is that a Handler is supposed to be the most efficient way of updating a UI element on a consistent and frequent basis, replacing java.util.Timer, but despite this my code starts out slow and just gets worst the longer I let it run.</p>
  
  <p>Even upon increasing the postDelay to 5000ms, the same problems still occured and the app still force closed after 49 minutes.  Since I would have thought this test would have extended the time til force-close by 5, if not fixing it altogether (at the detriment to the functionality I want), I'm suspecting that something isn't recycling right with the handler or some other component.</p>
  
  <p><strong>My Questions:</strong></p>
  
  <ul>
  <li>I suspect my problem is in having 7 objects (ActivityControls), each of which has <em>its own</em> Handler constantly cycling the update of the corresponding time that's displayed.  Does anyone have experience to say if this would be the case?  </li>
  <li>Is there a way I can have a <em>single</em> Handler that calls upon each ActivityControl in my ListView to update its time?  </li>
  <li>Does posting a message to the Handler leave some memory trace that doesn't dispose automatically, or might benefit from being forced to dispose?</li>
  <li>Does anyone else have other ideas about the most efficient way of running constant UI updates on multiple objects?</li>
  </ul>