07 Chapter Four Exercises

4-1 Which processes exist in the life cycle of an Android program, and how are the priorities of these processes arranged?

There are foreground process, visible process, service process, background process and empty process in the life cycle of Android program. Their priority from high to low
is foreground process, visible process, service process, background process and empty process.

4-2 Which 4 basic components are included in the Android system and what are their functions?

 Activity
Activity is the most basic module in the Android program. It is a visual user interface displayed for user operations. An Android application
can have only one activity or multiple activities. The role and number of each activity depend on For the application and its design.
 Service
Service means service. It has no visual user interface, but a program that runs in the background for a period of time.
 BroadcastReceiver
BroadcastReceiver (broadcast receiver) is a component that focuses on receiving broadcast notification information and making corresponding processing.
Many broadcasts in the Android program originate from the system, such as notification of time zone changes, low battery power, a photo taken, or the user changed language options, etc.; in addition,
Android applications can also broadcast, for example, you can In the downloader, other applications are notified that the data download is complete, etc.
The ContentProvider l
Content Provider is an interface mechanism for sharing data between applications is a more advanced method of data sharing, you can specify the required co-
sharing of data, while other applications you may not know the data source, path In case, operate on shared data.

4-3 Briefly describe the 4 states of Activity.

Activity is the most important part of an Android application. It mainly has 4 states, which are as follows:
 Running state: After a new Activity is launched into the stack, it is at the forefront of the screen and at the top of the stack. At this time, it is visible and
The activation state that can interact with the user .
 Paused state: The state when the Activity is covered by another transparent or Dialog style Activity. At this time, it is still connected to the window manager,
and the system continues to maintain its internal state, so it is still visible, but it has lost focus. It is not allowed to interact with users.
 Stopped state: When the activity is not visible, the activity is in the Stopped state. Activity will continue to keep
all current state and member information in memory . Assuming that memory is needed elsewhere in the system, it is the main candidate for the object to be recycled. When the Activity is in the
Stopped state, be sure to save the current data and the current UI state, otherwise once the Activity exits or closes, the current data and
UI state will be lost.
 Killed state: Activity is in Killed state after being killed or before being started. At this time, the Activity has been removed from the Activity stack and
needs to be restarted before it can be displayed and used.

4-4 In the life cycle of an Activity, what methods will be called back by the system?

 onCreate() method: Called back when the Activity is created. This method is the most common method. In Eclipse, when creating an Android project,
an Activity is automatically created. In this Activity, the onCreate(Bundle savedInstanceState) method is overridden by default to
initialize the Activity.
 onStart() method: It is called back when the Activity is started, that is, it is called back when an Activity becomes displayed.
 onRestart() method: Called back when the Activity is restarted, this method is always executed after the onStart() method.
 onPause() method: Called back when the Activity is paused. This method needs to be executed very quickly, because the
next Activity cannot be restored until this method is executed . In this method, it is usually used to persist data. For example, when we are playing a game,
a phone call suddenly comes , then we can use this method to save the game state permanently.
 onResume() method: called when the Activity is restored to the active state due to the suspended state. After calling this method, the Activity is at
the top of the Activity stack. This method is always executed after the onPause() method.
 onStop() method: Called back when the Activity is stopped.
 onDestroy() method: Called back when the Activity is destroyed.

4-5 What methods does the Log class provide for outputting log information, and what are their functions?

The Log class provides the following six common methods for outputting log information.
 v(): output VERBOSE redundant log information, expressed in black text
 d(): output DEBUG fault log information, expressed in blue text
 i(): output INFO notice information, expressed in green text
 w(): output WARN warning log information, expressed in orange text
 e(): output ERROR error log information, expressed in red text

4-6 What is a breakpoint? How to set and delete breakpoints in the program?

Setting breakpoints is an indispensable effective method in program debugging. Java debugger will suspend the current thread every time it encounters a program breakpoint, that is, suspend the
current program.
In the Java editor, the following 3 methods are provided to add or delete a breakpoint on the current line.
 Double-click the position where the code line number is displayed to add or delete the breakpoint of the current line;
 Right-click the position of the current line number, and select the "Switch Breakpoint" command in the pop-up shortcut menu to add and delete breakpoints .
 Position the cursor on the line where you want to set a breakpoint, and press <Ctrl+Shift+B> on the keyboard to add or delete a breakpoint.

4-7 What is Android Lint and how to use Android Lint?

Android Lint is a static analyzer for Android application code. It is a special program that can perform code error checking without code running. Android
Lint can usually find problems that the compiler can't find, and these problems are likely to cause the "Sorry, XXX has stopped running"
error when the project is running .
By default, Android Lint is not activated, if needed, it is required in the project name node, right-click the shortcut menu
list, select "Android Tools" / "Run Lint : Check for Common Errors" menu item , Open the Lint Warnings panel, in which the
checked errors or warnings will be displayed .

Guess you like

Origin blog.csdn.net/weixin_44522477/article/details/111867545