Android: Updating View from Background Thread

Issue:
 
For a small game application that I am currently working on, I needed to change the display text at certain intervals of time. Initially I tried to simply update the view(UI) using a timer class that runs after every 2 seconds. But I came across this error which says “Only the original thread that created a view hierarchy can touch its view.”
After some googling I came across a nice solution from Carlos Rodrigues site.
Basically, the solution involves creating a separate thread each time the update is required. The thread implements a Runnable interface to update the view which is executed using a Handler.

private final Handler myHandler = new Handler();

      
final Runnable updateRunnable = new Runnable() {
        public void run() {
            //call the activity method that updates the UI
              UpdateDisplayColor();
        }
       };
The thread which goes inside the onCreate method:
Thread thread = new Thread(new Runnable() {
                    
                     @Override
                     public void run() {
                           Timer t = new Timer();
                           t.scheduleAtFixedRate(
                                      new TimerTask()
                                      {
                                          public void run()
                                          {    
                                                doSomeHardWork();
                                          }
                                      },
                                      0,      // run first occurrence immediatetly
                                      2000); // run every two seconds     
                     }
              });
              thread.start();
 
And finally the implementation of the handler:
private void UpdateDisplayColor()
       {
              Random rand = new Random();
              index = rand.nextInt(4); //since there are only four colors         
              color = colors[index];
              TextView displayName= (TextView)findViewById(R.id.textView1);                           
       displayName.setText(color);             
       }
      
private void TimeToUpdateView()
    {        
        myHandler.post(updateRunnable);
        Log.d(“ColorName”,color);
    }
References:
http://crodrigues.com/updating-the-ui-from-a-background-thread-on-android/
http://developer.android.com/reference/android/os/Handler.html

SQL Improving Query Performance

1.     Use Indexes.
2.     Use All instead of UNION, OUTER UNION, EXCEPT and INTERSECT when you know there are no duplicate rows or when you know it does not matter whether duplicate rows are returned.
3.     Omit the ORDER BY clause unless necessary.
4.     Inline VIEWS or Temporary Tables?
      If the query is “long” and you are accessing the results from multiple queries, then use a Temporary Table to store the result from the query so that you can reuse it. Since a VIEW is just a select statement, the results need to be generated each time the view is called. Although subsequent runs of the view may be efficient because the results are stored in the cache, a temporary table actually stores the data.
5.     Use WHERE expressions with JOINS. JOINS without WHERE clause are often time consuming because of the ‘multiplier effect’ of the Cartesian Product.
6.     Replace multiple references to the DATE, TIME, DATETIME and ToDay functions in a single procedure. When the proc SQL ConstDateTime option or the SQLConstDateTime system option is set, proc SQL evaluates the date-time functions once through and uses the same result once throughout the whole query.