Activity
suggest changeIntroduction
An Activity represents a single screen with a user interface(UI). An Android App may have more than one Activity, for example, An email App can have one activity to list all the emails, another activity to show email contents, yet another activity to compose new email. All the activities in an App work together to create perfect user experience.
Syntax
- void onCreate(Bundle savedInstanceState) // Called when the activity is starting.
- void onPostCreate(Bundle savedInstanceState) // Called when activity start-up is complete (after onStart() and onRestoreInstanceState(Bundle) have been called).
- void onStart() // Called after onCreate(Bundle) — or after onRestart() when the activity had been stopped, but is now again being displayed to the user.
- void onResume() // Called after onRestoreInstanceState(Bundle), onRestart(), or onPause(), for your activity to start interacting with the user.
- void onPostResume() // Called when activity resume is complete (after onResume() has been called).
- void onRestart() // Called after onStop() when the current activity is being re-displayed to the user (the user has navigated back to it).
- void onPause() // Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.
- void onStop() // Called when you are no longer visible to the user.
- void onDestroy() // Perform any final cleanup before an activity is destroyed.
- void onNewIntent(Intent intent) // This is called for activities that set launchMode to “singleTop” in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent).
- void onSaveInstanceState(Bundle outState) // Called to retrieve per-instance state from an activity before being killed so that the state can be restored in onCreate(Bundle) or onRestoreInstanceState(Bundle) (the Bundle populated by this method will be passed to both).
- void onRestoreInstanceState(Bundle savedInstanceState) // This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState.
Parameters
Parameter | Details | —— | —— |Intent | Can be used with startActivity to launch an Activity |Bundle | A mapping from String keys to various Parcelable values. |Context | Interface to global information about an application environment. |
Remarks
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.