What is "android-activity"
Activity is a component that provides a graphical interface (UI), to allow the user to interact with the application.
Usually an application has more than one Activity, being the one that appears when starting considered as the main.
The application will provide some form of navigation to allow the user to "jump" between Activities, to perform each of the actions/activities of the application.
During navigation, the Android maintains a pile of Activities already open, allowing, using the button "Come back", return to Activity previous.
When a Activity is stopped due to the start of a new one, it is notified about that status change by means of the Lifecycle (Life Cycle) of Activity.
All activities on Android are subject to a Lifecycle. This cycle performs the notification work of Activity when certain events occur, allowing the application to respond appropriately if necessary. This happens from the moment an activity is started onCreate()
until the activity is eliminated onDestroy()
.
Due to the imposition of the Life Cycle in all activities, it is very important to be aware of when and what methods are called, as some of them may affect the stability of the application if not used correctly. Each method has its own arguments for processing and many are repeated throughout the life of the Activity.
The Life Cycle consists of the following methods:
onCreate()
onStart()
onResume()
onConfigurationChanged()
onRestoreInstanceState()
onPause()
onSaveInstanceState()
onStop()
onDestroy()
Minimum implementation requires:
- Inherit from the class Activity, or its sub-class (Activitycompat for example).
- Overwrite the method
onCreate()
, where it should be usedSetContentView()
to indicate the Layout to be used. - Declare the Activity in the Androidmanifest.xml, using the label
<activity>
Android Documentation: