Android Activity Lifecycle (AAL)

Android-based devices only have one foreground screen. Normally when you turn on Android, the first thing you see is the home. Then if you run a chess application, its User Interface (UI) will stack on top of the previous screen (home). Then if you see the chess help, the help UI will overwrite the previous UI (chess), and so on.

All the above processes are recorded in the application stack by the Activity manager system. Pressing the back button only returns to the previous page, the analogy is similar to a browser where when you click the back button the browser will return to display the previous page.

Each User Interface is represented by an Activity class. Each activity has a cycle, as seen in Figure 1.14. An application can consist of one or more activities that are processed in Linux. If you are confused by this explanation, don't think too much. Just keep going, you will understand after actually practicing the programming exercises later.

During this cycle, activity can have more than 2 statuses as seen in Figure 1.14. We cannot control each status because everything is handled by the system. However, we will get a message when a status change occurs through the onXX() method. Here is an explanation of each status.

  1. onCreate(Bundle) : Called when the application is first run. We can use this for variable declaration or creating user interface.
  2. onStart() : Indicates the activity displayed to the user.
  3. onResume() : Called when our application starts interacting with the user. This is perfect for placing animations or music.
  4. onPause() : Called when the application we are running returns to the previous page or usually because there is a new activity being run. This is suitable for placing the save algorithm.
  5. onStop() : Called when our application has been running in the background for a long time.
  6. onRestart() : Activity returns to displaying the user interface after the stop status.
  7. onDestroy() : Called when the application completely stops.
  8. onSaveInstanceState(Bundle) : This method allows the activity to save each instance state. For example, when editing text, the cursor moves from left to right.
  9. onRestoreInstanceState(Bundle) : Called when the activity re-initializes from the previous state saved by onSaveInstanceState(Bundle).

As a programmer, you must know some very important application components such as activities, intensity, services, and content providers.

a. Activity

Normally each activity displays one user interface to the user. For example, an activity displays a list of drink menus, then the user can choose one type of drink. Another example is in an SMS application, where one activity is used to write a message, the next activity to display the destination contact number, or another activity is used to display old messages. Although the activities above are in one SMS application, each activity stands alone. To move from one activity to another, you can do an event, for example, a button is clicked or through a certain trigger.

b. Service

Service does not have a user interface, but runs behind the scenes. For example, a music player, an activity is used to select a song and then play it. In order for the music player to run behind other applications, it must use a service.

c. Intense

Intense is a mechanism for describing an action in detail, such as how to take a photo.

d. Content Providers

Provide a way to access data needed by an activity, for example we use a map-based application (MAP). Activity needs a way to access contact data for navigation procedures. This is where the role of content providers comes in.

e. Resources

Resources are used to store non-coding files needed in an application, such as icon files, image files, audio files, video files or others. JPG or PNG images of an application are usually stored in the res/drawable folder, application icons are stored in res/drawable-ldpi and audio files are stored in the res/raw folder. XML files to form a user interface are stored in the res/layout folder.


Post a Comment

Previous Next

نموذج الاتصال