i posted a question (here) about how to change UI elements in a timer task, this is fine now.
but when i have a code like this:
countInt = 0;
timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
countInt = countInt + 1;
}
}, 1000);
the counterInt var is saved in the activity where also this code is in.
how to change this value without crashing?
I think there are two possibilities:
1) Make countInt into an Integer object and synchronize access to it EVERYWHERE you use it:
2) Use the AtomicInteger, which might even work better, as it does not block any threads. This prevents the UI from locking up.