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();
}
}