Q:

Updating Android UI

This function resides in a Service when called by an activity it should will generate a random number and add that to a ArrayList.  Everytime a new item is added it will try to update UI via update which calls runOnUiThread to use these number to plot a line graph and then wait 1 second.  I want the update to happen every second.  Is there a way to force activity to clear execute its message queue?  As of right now it waits until this thread finish executing before it updates.  Should I implement this in AsyncTask instead? 
public void pollDP(int numPt){
    final Random gen = new Random();
    final int numPtF = numPt;
    serverLoadList = new ArrayList<Integer>();

        new Thread(new Runnable(){
            @Override
            public void run(){
                for(int i = 0; i < numPtF; i++){
                    serverLoadList.add(gen.nextInt());
                    update();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
            }

        }).run();
    }
}

A:

The solution is in the comment on my question by Martze.  I am making this the solution for my problem. 

try using Thread.start() instead of Thread.run().  If you use run(), the Runnable is not launched in a new Thread.  If this didn't help, post some code of the update() method.  Am i right by guessing you are calling pollDP from UI-Thread? –  Martze 

