Android - 允许使用暂停,恢复的任何计时器组件

时间:2015-12-01 01:32:13

标签: android timer countdowntimer

我正在使用简单的countDownTimer

class Array
  def find_indices(*args)
    h = each_with_index.with_object(Hash.new {|h,k| h[k] = []}) { |(n,i),h| h[n] << i }
    args.each_with_object([]) { |n,a| v=h[yield n]; a << v.shift if v }
  end
end

arr.find_indices(*findees) { |n| n**2 }
  #=> [1, 5, 0, nil, 4, nil]

arr = [3,1,2,1,3,6,5]
findees = [1,6,3,6,3,7]
arr.find_indices(*findees, &:itself)
  #=> [1, 5, 0, nil, 4, nil]

但现在,我想打电话给

  

countDown.pause(); countDown.resume();

(以这种方式存储剩余时间和进度):

我知道CountDownTimer是不可能的。

如何使用计时器或处理程序与CountDownTImer的 onFinish()方法的相同行为?

1 个答案:

答案 0 :(得分:1)

这是一个非常好的库,可以完全按照您的要求进行操作:pause-resume-timer

它基本上是Timer的子类。一个非常好用的库。您所需要做的就是:

//This creates a timer which ticks every 2 seconds, and runs for 20 seconds.
Timer twoSecondTimer = new ExampleTimer(2000l, 20000l);
//Start the timer.
twoSecondTimer.start();
//Pause the timer.
twoSecondTimer.pause();
//Resume the timer
twoSecondTimer.resume();