I have a animated loader in my application right now.
public void startLoader() {
Runnable task = new Runnable() {
@Override
public void run() {
lock = true;
loader.setVisibility(View.VISIBLE);
}
};
runOnUiThread(task);
}
public void stopLoader() {
Runnable task = new Runnable() {
@Override
public void run() {
lock = false;
loader.setVisibility(View.GONE);
}
};
runOnUiThread(task);
}
Now I want it to work like this:
stopLoader should have an delayed execution of like 1000ms, so it dissapears 1 second after stopLoader is called. but if the startLoader is called within that 1000ms the stopLoader timer would be cancelled.
What is the best way to implement this?