【问题标题】:Count Down Timer For Entire Activity整个活动的倒计时
【发布时间】:2014-02-04 06:30:33
【问题描述】:

我有多个活动例如说 N 个活动
当活动开始时,倒计时开始
这是我的问题?
倒数计时器启动后,我想切换到另一个活动。因此,当活动更改为另一个时,倒数计时器应该恢复..
谁能用合适的例子给我答案
提前致谢

【问题讨论】:

  • 当一个活动开始倒计时开始这个只有我试过了

标签: android android-activity countdowntimer


【解决方案1】:

通过意图将计时器的开始时间发送到另一个活动。所以:

long timerStarted = System.currentTimeMillis();

Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("timerStarted", timerStarted);

然后在下一个活动中使用

getIntent().getLongExtra("timerStarted", System.currentTimeMillis());

您将保持计时器与其在上一个活动中的开始时间一致。

【讨论】:

    【解决方案2】:

    您可以使用与 splashScreen 中相同的代码。

    new Handler().postDelayed(new Runnable() {
    
                /*
                 * Showing splash screen with a timer.
                 */
    
                @Override
                public void run() {
                    // This method will be executed once the timer is over
                    Intent i = new Intent(Act1.this, Act2.class);
                    startActivity(i);
                    // close this activity
                    finish();
                }
            }, SPLASH_TIME_OUT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多