I am very new to the android platform thus java so i have a pretty basic question i am trying to make a simple second timer so here is the code i have written. I don’t know why but the method run never gets executed:
Timer tmr = new Timer();
tmr.schedule(new TimerTask()
{
@Override
public void run() {
TextView txt = (TextView) findViewById(R.id.txtLoading);
counter++;
txt.setText(counter);
}
}, 1000);
LE : actually it looks like it executing but the GUI doesn’t get updated … why ?
Using Timer like that creates a new Thread, and updating the GUI from a thread which is not the main thread is not a good idea.
A better approach is the one reported in this link: http://developer.android.com/resources/articles/timed-ui-updates.html
Hope it helps!