我在我的应用程序中实现了倒数计时器。它在后台运行得很好而且花花公子,但是当我使用高级任务杀手时,它会停止计时器并且重新启动它的唯一方法是再次打开应用程序。无论如何,即使我使用高级任务杀手之类的东西,计时器是否仍然存在?
代码:
TextView tv;
final MyCounter timer = new MyCounter(10000,1000);
tv = (TextView)findViewById(R.id.healthtext);
tv.setText("10");
timer.start();
}
public class MyCounter extends CountDownTimer{
public MyCounter(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
Toast.makeText(getApplicationContext(), "death", Toast.LENGTH_LONG).show();
}
@Override
public void onTick(long millisUntilFinished) {
tv.setText((millisUntilFinished/1000)+"");