问题
I am using handler.postDelayed method to create some delay for some animation stuff. Like this:
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
// Start Animation.
}
}, 6000);
Later, How can I get the remaining time until the animation starts?
回答1:
You can simply save the time in a var when you call post delayed
long startTime = System.nanoTime();
h.postDelayed(...
and then when you need to check the remaining time you can calculate the elapsed time like
long elapsedTime = System.nanoTime()-startTime;
So in your case
long remainingTime = 6000 - elapsedTime;
来源:https://stackoverflow.com/questions/25285326/get-remaining-time-when-using-handler-postdelayed