Starting an Activity
Start an activity
Previous NextGet started This lesson teaches you
This course teaches you the following:
Understand the Lifecycle Callbacks Understand the Lifecycle callback Specify Your App's Launcher Activity specifies the startup Activity of the application Create a New Instance to Create a New case Destroy the Activity to Destroy this Activity You should also readActivitiesTry it outDownload the demo
ActivityLifecycle.zip
Unlike other programming paradigms in which apps are launched withmain()Method, the Android system initiates code inActivityInstance by invoking specific callback methods that correspond to specific stages of its lifecycle. There is a sequence of callback methods that start up an activity and a sequence of callback methods that tear down an activity.
Unlike other programming paradigms where an application has a main () method, the Android system starts code in an Activity case by calling a specific callback method at a specific lifecycle stage. There are a series of callback methods to start an activity and use a series of callback methods to split an activity.
This lesson provides an overview of the most important lifecycle methods and shows you how to handle the first lifecycle callback that creates a new instance of your activity.
This section provides an overview of the most important declarative cycle method, showing you how to handle the first lifecycle callback for the activity of the newly created instance ,.
Understand the Lifecycle Callbacks Understand Lifecycle callback
During the life of an activity, the system calla core set of lifecycle methods in a sequence similar to a step pyramid. that is, each stage of the activity lifecycle is a separate step on the pyramid. as the system creates a new activity instance, each callback method moves the activity state one step toward the top. the top of the pyramid is the point at which the activity is running in the foreground and the user can interact with it.
In the life process of an activity, the System Call of the life cycle method presents a set of core sequences similar to step pyramid. That is, each stage of the activity lifecycle is an independent step on the pyramid. When the system creates a new active instance, each callback method moves one step to the top. The top of the pyramid is a dot activity that runs on the front end and can be interacted with by users.
As the user begins to leave the activity, the system callother methods that move the activity state back down the pyramid in order to dismantle the activity. in some cases, the activity will move only part way down the pyramid and wait (such as when the user switches to another app ), from which point the activity can move back to the top (if the user returns to the activity) and resume where the user left off.
When the user starts to leave the activity, the system calls other methods to return the activity status to the pyramid to split the activity. In some cases, the activity will only move a part or wait along the pyramid (for example, when the user switches to another application ), the activity at this point can return the top (if the user returns to the activity) and continue from the place where the user leaves.
Figure 1.A simplified authentication of the Activity lifecycle, expressed as a step pyramid. this shows how, for every callback used to take the activity a step toward the Resumed state at the top, there's a callback method that takes the activity a step down. the activity can also return to the resumed state from the Paused and Stopped state.
A simplified example of the lifecycle of an activity is represented as a tiered pyramid. This indicates that each callback is used to restore the activity step to the top and there is a callback method to step down the activity. The activity can return to the pause and stop statuses.
Depending on the complexity of your activity, you probably don't need to implement all the lifecycle methods. however, it's important that you understand each one and implement those that ensure your app behaves the way users wrong CT. implementing your activity lifecycle methods properly ensures your app behaves well in several ways, including that it:
Based on the complexity of your activities, you may not need to implement all lifecycle methods. However, it is important that you understand every method and implementation that the user expects to ensure the behavior of the application. The implementation of your normal activity lifecycle method can ensure the behavior of your application in several aspects, including:
Does not crash if the user has es a phone call or switches to another app while using your app.
If a user receives a call or switches to another application when using your application, it will not crash.
Does not consume valuable system resources when the user is not actively using it
When you use it, it does not consume valuable system resources.
Does not lose the user's progress if they leave your app and return to it at a later time.
If they leave your application and return it within a while, do not lose the user's process.
Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.
Processes that do not crash or lose users when the screen is rotated horizontally or vertically.