Android Application Test Questions enhanced on the basis of the enhanced version
Some Supplements are slightly bloated, just for learning
1. lifecycle of the activity.
Method
Description
Can be killed
Next
OnCreate ()
Called when the activity is created for the first time. Here is where you do all the initialization settings-create a view, set the layout, and bind data to the list. If a status record exists (see Saving Activity State later .), When this method is called, a package object containing the previous status of the activity is passed as the parameter.
It is followed by onStart ().
No
OnStart ()
OnRestart ()
OnStop () after the activity is stopped and called before the activity is restarted.
It is followed by onStart ().
No
OnStart ()
OnStart ()
Called when the activity is about to become visible to the user.
When the activity turns to the foreground, it follows onResume () and onStop () when the activity turns to hidden ().
No
OnResume ()
Or
OnStop ()
OnResume ()
Called before the activity starts to interact with the user. In this case, the activity is at the top of the stack and user input is accepted.
Followed by onPause ().
No
OnPause ()
OnPause ()
Called when the system is about to start another activity. This method is mainly used to persist unsaved changes and stop CPU-consuming actions like animations. All these actions should be completed in a short time, because the next activity must wait until this method is returned to continue.
When the activity returns to the foreground again, it is followed by onResume (). When the activity becomes invisible to the user, it is followed by onStop ().
Yes
OnResume ()
Or
OnStop ()
OnStop ()
This method is called when the activity is no longer visible to the user. This may happen when it is destroyed or another activity (which may be existing or new) returns to the running state and overwrites it.
If the activity returns to the foreground again to interact with the user, it is followed by onRestart (). If the activity is disabled, it is followed by onDestroy ().
Yes
OnRestart ()
Or
OnDestroy ()
OnDestroy ()
Called before activity destruction. This is the last call received by the activity. This may occur when the activity ends (the finish () method is called) or the instance of this acitivity is temporarily destroyed because the system needs space. You can use the isFinishing () method to differentiate the two cases.
Yes
Nothing
(Supplement)
1. onCreate (): called when the Activity is created (the first time ). Operation: Set layout files, initialize views, and bind data files.
2. onStart (): When the Activity can be seen by us.
3. onResume (): When the Activity gets the focus of the user, it can be operated by the user.
4. onPause () [pause meaning]: Activity pause. When the application starts another Activity. Example: when a call is made, the system starts the call Activity. What we need to do in this function is to save the Activity data. After answering the call, we will read the data and restore the original Activity.
5. onstop (): When the second Activity completely blocks the first Activity. The dialog box does not completely block the original Activity and will not be called.
6. onDestroy (): destroys an Activity. 1) The finish () method is called. 2) Insufficient system resources.
Function call process:
When starting the first Activity:
When onCreate () --> Activity is created for the first time, onStart () --> Activity can operate onResume ().
Click the button on the first Activity to jump to the second Activity through Intent:
The first Activity pauses onPause () --> creates the second ActivityonCreate () --> Activity visible onStart () --> Activity can operate onResume () --> the first Activity is completely overwritten by the second Activity onStop () (if finish () is called or the system resources are insufficient, onDestory () is destroyed ()).
Click system return function creation, and return to the first Activity from the second Activity:
The second Activity pauses onPause () --> the first Activity restarts OnRestart () (not destroyed. If yes, create onCreate ()) --> the first Activity is visible to onStart () --> the first Activity can operate onResume () --> The second Activity is completely overwritten with onStop () (if finish () is called (), or if the system resources are insufficient, onDestory () will be destroyed ()).
2. lifecycle of the activity during horizontal and vertical screen Switching
1. When the android: configChanges of the Activity is not set, the split screen will call the lifecycle of each Activity again. The split screen will be executed once, and the split screen will be executed twice.
Author: superjunjin
2. When you set the Activity's android: configChanges = "orientation", the screen will be switched to call the life cycle again, and the screen will only be executed once.
3. When the android: configChanges = "orientation | keyboardHidden" of the Activity is set, the live cycle is not re-called and only the onConfigurationChanged method is executed.
3. What are the features and differences of animations in android?
Android provides two simple animation creation mechanisms: tweened animation and frame-by-frame animation ).
Tweened animation: animated effects are generated by constantly performing image transformations (translation, scaling, and rotation) on objects in the scenario.
Frame-by-frame animation: plays images prepared in advance in sequence, similar to movies.
Both animation types can be used in any View object to provide simple rotation timers, activity icons, and other useful UI elements. Tweened animation is operated by the andorid. view. animation package; frame-by-frame animation is operated by the android. graphics. drawable. AnimationDrawable class.
Want to know