Some knowledge points about Activity, window and view

Reference from the book "Android Mobile Development"

The priorities of Android processes from high to low are foreground process, visible process, service process, background process and empty process.
Insert image description here

  1. Foreground process: It is the most important process in the Android system and is the process that interacts with the user. Its importance is of the highest order. Generally, it can be regarded as a foreground process if the following conditions are met:

a. The process is running an Activity that interacts with the user at the front end [Activity's onResume() method is called]
b. There is a running BroadcastReceiver in the process [BroadcastReceiver.onReceive() method is being executed]
c. There is a Service, and there is code being executed within a callback function of the Service.

  1. Visible process: refers to a process in which part of the program interface can be seen by the user, but does not interact with the user in the foreground and does not affect interface events. Generally, a process can be considered visible if the following conditions are met:

a. There is an Activity that is not in the foreground but is still visible to the user [Activity's onPause method is called]. For example, the foreground Activity is a dialog box, and the previous Activity is still partially visible, that is, the process to which the previous Activity belongs is a visible process.
b. Have a Service bound to the visible Activity.

  1. A service process refers to a process that contains a started service. •No user interface •Long running in the background

  2. Background processes: Background programs run activities that are invisible to the user [Activity's onStop method is called]. These processes have no direct impact on the user experience.

There are generally a large number of background processes in the Android system. When system resources are tight, the system will give priority to clearing background processes that the user has not seen for a long time.

  1. Empty processes are processes that do not contain any active components and may be shut down by the system at any time.

Insert image description here

The four states of Activity:
Insert image description here
  Generally, we will save the current data and the current UI state in the onStop method, and at the same time save important data in the onPause method.
  The execution time required by the onPause method in the Android system is "short" because an Activity needs to be started immediately, so there cannot be too much processing in the onPause method.
Insert image description here
The basic user interface
  View can be understood as a view in Android. It occupies a rectangular area on the screen and is responsible for providing methods for component drawing and event handling. The View class is the base class for all widget components. For example, TextView (text box), EditText (edit box), and Button (button) are all widget components.
  The View class is located in the android.view package; the text box component TextView is a subclass of the View class and is located in the Android.widget package.
  ViewGroup can be understood as a container in Android. The ViewGroup class inherits from the View class. It is an extension of the View class and is a container used to accommodate other components. However, since ViewGroup is an abstract class, its subclasses are usually used as containers in practical applications, such as layout. container.
  In Android, all UI interfaces are composed of the View class, the ViewGroup class and its subclasses. In the ViewGroup class, in addition to the ordinary View class, you can also include the ViewGroup class again. In effect, this uses the Composite design pattern. The hierarchy of UI components is as follows:
Insert image description here

Padding and Margins
  Padding represents the padding pixels at the top, bottom, left and right sides of the View. It is also called padding. It sets the distance between the content and the edge of the View. Padding will occupy part of the height and width of the View.
  Margins represent the blank space at the top, bottom, left, and right of a component, called margins. It sets the distance between the component and the parent container. Margins do not occupy the width and height of the View component. When margins are set for a component, the component will be positioned a specified distance away from its parent container and, if there are adjacent components, its adjacent components as well.
  The difference between Padding and Margins is as follows:
Insert image description here
px, dp and sp
  px (Pixels, pixels): Each px corresponds to a point on the screen. For example, 1024x720 resolution
  dp (set independent pixel): an abstract unit based on screen density, dip can also be used. On a 160 dots per inch monitor, 1dp=1px. But as the screen density changes, the conversion of dp to px will also change.
  sp (proportional pixels): mainly deals with the size of fonts, which can be scaled according to user font size preferences.

Guess you like

Origin blog.csdn.net/suwen8100/article/details/118226326