I need to update UI after certain time period, for which I have create a timer schedule and inside it I am calling the runOnUiThread.
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
System.out.println("1");
try {
System.out.println("2");
System.out.println("3");
runOnUiThread(new Runnable() {
public void run() {
System.out.println("4");
System.out.println("5");
System.out.println("6");
System.out.println("7");
}
});
System.out.println("8");
} catch (Exception e) {
e.printStackTrace();
}
}
}, delay, period);
System.out.println("9");
I am having the problem that after reaching "3", timer thread jumps to "8" and after that the UI thread runs from "4". I want to make timer thread to wait till UI thread completes its work at "7" only then it should move to "8".
Sample Output
01-05 00:30:16.308: I/System.out(1394): 1
01-05 00:30:16.308: I/System.out(1394): 2
01-05 00:30:16.308: I/System.out(1394): 3
01-05 00:30:16.308: I/System.out(1394): 8
01-05 00:30:16.308: I/System.out(1394): 4
01-05 00:30:16.308: I/System.out(1394): 5
01-05 00:30:16.308: I/System.out(1394): 6
01-05 00:30:16.308: I/System.out(1394): 7
01-05 00:30:17.307: I/System.out(1394): 1
01-05 00:30:17.307: I/System.out(1394): 2
01-05 00:30:17.307: I/System.out(1394): 3
01-05 00:30:17.307: I/System.out(1394): 8
01-05 00:30:17.307: I/System.out(1394): 4
01-05 00:30:17.323: I/System.out(1394): 5
01-05 00:30:17.323: I/System.out(1394): 6
01-05 00:30:17.323: I/System.out(1394): 7