Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 整个活动的倒计时_Android_Android Activity_Countdowntimer - Fatal编程技术网

Android 整个活动的倒计时

Android 整个活动的倒计时,android,android-activity,countdowntimer,Android,Android Activity,Countdowntimer,我有多个活动,比如说N个活动 当活动开始时,倒计时开始 这是我的问题吗? 倒计时开始后,我想切换到另一个活动。这样,当活动更改为另一个活动时,倒计时应该恢复。… 有人能给我一个合适的例子来回答吗 提前感谢通过意向将计时器的开始时间发送给其他活动。因此: long timerStarted = System.currentTimeMillis(); Intent intent = new Intent(this, AnotherActivity.class); intent.putExtra("

我有多个活动,比如说N个活动
当活动开始时,倒计时开始
这是我的问题吗?
倒计时开始后,我想切换到另一个活动。这样,当活动更改为另一个活动时,倒计时应该恢复。…
有人能给我一个合适的例子来回答吗

提前感谢

通过意向将计时器的开始时间发送给其他活动。因此:

long timerStarted = System.currentTimeMillis();

Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("timerStarted", timerStarted);
然后在下一个活动中使用

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

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

您可以使用与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);

当一个活动开始倒计时时,开始这一步,直到目前为止我才尝试过