Android studio暂停和恢复倒数计时器进度条

时间:2016-11-02 15:06:48

标签: android-studio timer progress-bar countdowntimer

我正在使用倒计时器更新我的进度条,从100(完整)减少到0(空)但暂停应用程序时暂停计时器,然后在恢复应用程序时重新启动它。我像这样实现了倒计时器:

public class MyCountDownTimer extends CountDownTimer {


    public MyCountDownTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        int progress = (int) (millisUntilFinished / 100);
        progressBar.setProgress(progress);
    }

    @Override
    public void onFinish() {
        progressBar.setProgress(0);
        Intent intent = new Intent(getApplicationContext(), GameOver.class);
        startActivity(intent);
        finish();
    }

}

在我的创作中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_screen);

    progressBar = (ProgressBar)findViewById(R.id.timerBar);
    progressBar.setProgress(100);
    myCountDownTimer = new MyCountDownTimer(10000, 10);
    myCountDownTimer.start();
}

1 个答案:

答案 0 :(得分:0)

您可以在 MyCountDownTimer 类中添加一个布尔值,该布尔值将在活动import fnmatch for i, (dirpath, dirs, files) in enumerate(os.walk(path)): if i == 0: # Top level dir, prune non-Project dirs dirs[:] = fnmatch.filter(dirs, 'Project *') elif os.path.samefile(os.path.dirname(dirpath), path): # Second level dir, prune non-TARGET dirs dirs[:] = fnmatch.filter(dirs, 'TARGET') else: # Do whatever handling you'd normally do for files and directories # located under path/Project */TARGET/ onPause方法中更改。查看onResume条评论,了解为完成此项工作所需进行的更改。

// ADDED