Activity interview questions, activity questions
What is Activity?
Activity is one of the four main components of Android. Generally, a user interface corresponds to an Activity. At the same time, Activity is a subclass of Context, and it also implements the Window interface and KeyEvent interface to process the Window-User Interaction Events.
Briefly describe the lifecycle of the Activity
Activity lifecycle can be dividedTypical LifecycleAndLifecycle in case of exceptionsIn two ways.
The typical lifecycle is as follows:
Opening an Activity will call
OnCreate-onStart-onResume is called when an Activity is closed.OnPause-onStop-onDestroy is called when a foreground Activity is blocked by a dialog box or overwritten by a translucent or transparent Activity.OnPause, called when you return to the front-endOnResume; called when an Activity is invisible to the visibleOnRestart-onStart-onResume is called when you press the Home Key to return to the desktop.OnPause-onStop; A calls back A'sOnPause, and then callback B'sOnCreate-onStart-onResume, and then call backOnStop; returns data from Activity B to Activity A, and calls back the data of Activity B first.OnPause, and then callback A'sOnRestart-onStart-onResume.onStop - onDestroy;
The lifecycle of an exception is as follows:
In general, there are two situations that cause abnormal Activity destruction. One is caused by horizontal and vertical screen switching, but by insufficient system resources, the Activity with a lower priority is destroyed by the system. If the Activity is configured in the list fileAndroid: configChanges = "orientation | screenSize", the Activity will not be destroyed and rebuilt during landscape/portrait switching. OnlyThe onConfigurationChanged method is executed when the Activity is destroyed.OnPause-onSaveInstanceState-onStop-onDestroy, which will be executed during reconstructiononCreate - onStart - onRestoreInstanceState - onResume