I do have a button and when this button is clicked I want to do some actions and revert them back, in lets to say 5 secs. Example, when Button A is clicked, TextA.Text becomes “Clicked” for 5 secs, in 5 secs the value of text should come back to its original. Here what I do have, but I feel that it is totally wrong way. The code that do delay:
diff=time2-time1;
while (diff<5000) {
//Log.d("Timer is", String.valueOf(diff));
time2=System.currentTimeMillis();
diff=time2-time1;
}
so untill loop is working its simulate delay and after i do what i want. Any advice?
Use a Handler, something like this:
Edit: Note that this solution allows the main thread to continue during the delay – refreshing the GUI, handling activity changes (such as “Home” button) correctly, etc. Using
Thread.sleep()does not.