如何在应用启动时设置倒数计时器的值

问题描述 投票:0回答:2

[嘿,我有一个倒数计时器,用来向用户显示我的应用程序还剩多少时间。但是现在我想如果计时器运行1分钟,并且用户在30秒后关闭应用程序,然后在接下来的5秒内用户再次打开应用程序,那么时间应该从剩余的25秒开始运行]]

    CountDownAdapter countDown = new CountDownAdapter(60*1000, 1000);
                countDown.setSourceActivity(MainActivity.this);
                countDown.start();

 public void onCountDownTimer(long millisUntilFinished)
    {
        secondsLefts = millisUntilFinished;
        long secondsLeft = millisUntilFinished / 1000;
        long hours = secondsLeft / 3600;
        long minutes = (secondsLeft % 3600) / 60;
        long seconds = secondsLeft % 60;
       timerText = hours + "h: "+minutes + "m: "+seconds + "s";

        if(timerText.equals("0h: 0m: 1s"))
        {

        }
        timer.setText(timerText);
    }

[嘿,我有一个倒数计时器,用来向用户显示我的应用程序还剩多少时间。但是现在我想如果计时器运行1分钟,并且用户在30秒后以及接下来的5秒内关闭应用程序...

android countdown countdowntimer
2个回答
1
投票

应用程序的生命周期看起来像this


0
投票

您可以遵循这是如何执行需求的想法,但是该技术存在问题。

© www.soinside.com 2019 - 2024. All rights reserved.