I'm new to Android programming. What I want to do is to swith to an another activity that has already been created. Suppose I started Activity B and move from Activity A to Activity B, and then I pressed back button and move back to Activity A. Now I want to switch to Activity B when a countdown timer is done.
ActivityA.java
private void startTimer() {
...
@Override
public void onFinish() {
// force the user to move on to Activity B
// if the user haven't started Activity B, just start it
if (!mHasActivityBStarted) {
Intent intent =
new Intent(ActivityA.this, ActivityB.class);
startActivity(intent);
} else {
// how can I switch to ActivityB that has been created?
}
}
}.start();
}
How can I do it?
From Android Developer documentation
In your case, you can switch between
ActivityA
andActivityB
without finishing or recreating them.Put it together.
ActivityA
ActivityB