Introduction of Activity Lifecycle
This section describes the android.app.Activity class which represents an activity you allow the user to interact with on the screen. An activity has 4 states: Active, Paused, Stopped and Destroyed.
In the last chapter, we learned how to access the Android application environment information using
the java.lang.System and android.os.Environment classes.
Now let's take a closer look at the starting class of our simple applications created so far: android.app.Activity.
The android.app.Activity class represents an activity you allow the user to interact with on the screen.
The android.app.Activity class takes care of creating an empty window for you to place visual content using
the setContentView() method.
An Activity object has four states:
- Active - If an activity in the foreground of the screen (at the top of the stack), it is active or running.
- Paused - If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.
- Stopped - If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
- Destroyed - If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.
Android reference document provides the following diagram to illustrate the lifecycle
of an Activity object:
The entire lifecycle of Activity object is divided into 3 nested lifetime periods:
- Entire lifetime - The period between the moment the activity is created and
the moment the activity is destroyed.
- Visible lifetime - The period between the moment the activity is started
showing on the screen and the moment the activity is stopped showing on the screen.
- Foreground lifetime - The period between the moment the user resumes
interaction with this activity and the moment the user switches to other activities
leaving this activity paused.
See next tutorials on you can add code logics when the activity
entering or leaving a lifetime period.
Last update: 2015.
Table of Contents
About This Book
Installing JDK 1.8 on Windows System
Installation of Android SDK R24 and Emulator
Installing Apache Ant 1.9 on Windows System
Developing First Android Application - HelloAndroid
Android Application Package (APK) Files
Android Debug Bridge (adb) Tool
Android File Systems
Android 4.0.3 File Systems
AboutAndroid - Application to Retrieve System Information
►android.app.Activity Class and Activity Lifecycle
►Introduction of Activity Lifecycle
onCreate() and Other Callback Methods
ActivityLog - Application to Create Log File
Viewing Activity Log File with "cat" Command in "adb shell"
Implementing Activity Callback Methods
ActivityLog Test - Activity Terminated by User
ActivityLog Test - Activity Stopped and Restarted
ActivityLog Test - Activity Paused and Resumed
View Objects and Layout Resource Files
Using "adb logcat" Command for Debugging
Build Process and Package File Content
Building Your Own Web Browser
Android Command Line Shell
Samsung Galaxy Tab 3 Mini Tablet
USB Debugging Applications on Samsung Tablet
Android Tablet - LG-V905R
USB Debugging Applications on LG-V905R Tablet
Android Phone - LG-P925g
USB Debugging Applications on LG-P925g Phone
PDF Printing Version