An Android app can contain multiple activity, and an activity can initiate another activity.
The activity is managed with a stack structure, and the newly opened activity is stacked on top of the current activity, and the current activity stops running.
When an activity stops running, the Android system retains its pre-stop state, and when the user presses the "Back" button, the top activity of the stack is rolled out of the stack and the previous activity moves to the top of the stack and is displayed on the screen:
Sometimes, when an activity launches a new activity, it does not want to keep the activity in the activity stack, such as when a confirm dialog is implemented using activity, and when the user confirms that a new activity is initiated, Do not want to display confirm Dialog when the new activity is displayed by pressing "back".
Example fowarding uses finish () to end the current activity while starting a new activity.
// Here we start the next activity, and then call Finish () // So, our own would stop running and is removed from the // History stack. New Intent (); Intent.setclass (Forwarding. this, forwardtarget. class ); StartActivity (intent); Finish ();
Finish finishes forwarding Activity, and then presses "back", then directly to the Apidemo->activity sample list instead of the forwarding interface.
Sail plan 007 2015 sail plan Android Apidemo Devil Step app->activity->forwarding activity start another activity finish () method