Reputation: 278
Am having multiple activity For example say N number of activities
When an activity starts the countdown timer begins
Here my question?
After the countdown timer starts I want to switch over to another activity.so that time the count down timer should be resume when the activity changed to another ....
Can any one give me the answer with suitable example
Thanks in advance
Upvotes: 0
Views: 476
Reputation: 1478
You can use the same code as used in 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);
Upvotes: 0
Reputation: 1159
Send the starting time of the timer to another activity via an intent. So:
long timerStarted = System.currentTimeMillis();
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("timerStarted", timerStarted);
Then in the next activity use
getIntent().getLongExtra("timerStarted", System.currentTimeMillis());
You will keep the timer consistent with its start time in the previous activity.
Upvotes: 1