Try something like this:
private Runnable myRunnable = new Runnable() {
public void run() {
txtStatus.setText("hello");
}
};
// somewhere in code
txtStatus.postDelayed(myRunnable, 1000);
// in onPause or onDestroy
txtStatus.removeCallbacks(myRunnable);
Notes:
- this avoids memory leaks, as your
run
will never be called afteronDestroy
if you callremoveCallbacks
- I replaced
new Handler()
withtxtStatus
, because everyView
has its own instance ofHandler
and there is no need to create additional one