Hello I am trying to update the textview at every certain time, but it only updates the first and then it force closes, here is the code:
try {
timer = new Timer();
timerTask = new TimerTask() {
@Override
public void run() {
//Download file here and refresh
updateRecSMSCount(count);
}
};
timer.schedule(timerTask,0, 3000);
} catch (IllegalStateException e){
}
void updateRecSMSCount(Integer count)
{
TextView numRecSMS=(TextView)findViewById(R.id.numRecSMS);
numRecSMS.setText(count.toString());
}
Can someone help please?
You can’t access the UI from other thread than the thread that created the UI. The timer task runs in different thread. You can find solutions here: Updating the UI from a Timer
The most simple repair is: