Podcast
Questions and Answers
What happens to an Activity when it is in the 'Destroyed' state?
What happens to an Activity when it is in the 'Destroyed' state?
- It is still visible to the user.
- It is removed from memory. (correct)
- It can transition back to the 'Started' state.
- It is partially visible to the user.
Which state indicates that an Activity is visible to the user but not in the foreground?
Which state indicates that an Activity is visible to the user but not in the foreground?
- Paused (correct)
- Created
- Stopped
- Resumed
What event can trigger state changes in an Activity?
What event can trigger state changes in an Activity?
- User interaction. (correct)
- Application installation.
- System file updates.
- Internet connectivity loss.
Which of the following states is NOT a part of the Activity lifecycle?
Which of the following states is NOT a part of the Activity lifecycle?
Which state signifies that the Activity is currently active and in the foreground?
Which state signifies that the Activity is currently active and in the foreground?
What happens during the onCreate() callback in an Android Activity lifecycle?
What happens during the onCreate() callback in an Android Activity lifecycle?
Which callback is triggered when an Activity is no longer visible to the user?
Which callback is triggered when an Activity is no longer visible to the user?
During which callback would an Activity start to interact with the user after being obscured?
During which callback would an Activity start to interact with the user after being obscured?
What occurs in the onPause() callback of an Activity lifecycle?
What occurs in the onPause() callback of an Activity lifecycle?
What function does the onRestart() callback serve in the Android Activity lifecycle?
What function does the onRestart() callback serve in the Android Activity lifecycle?
What method is called only once during the lifecycle of an activity?
What method is called only once during the lifecycle of an activity?
Which method is called immediately after onCreate()?
Which method is called immediately after onCreate()?
What is the purpose of the Bundle parameter in onCreate()?
What is the purpose of the Bundle parameter in onCreate()?
How many times can the onStart() method be called during an activity's lifecycle?
How many times can the onStart() method be called during an activity's lifecycle?
Which of the following statements about the activity lifecycle is true?
Which of the following statements about the activity lifecycle is true?
Which lifecycle method is primarily responsible for finalizing the creation of the activity?
Which lifecycle method is primarily responsible for finalizing the creation of the activity?
What should you expect immediately after the onCreate() method is executed?
What should you expect immediately after the onCreate() method is executed?
What occurs if there was previously saved state during the activity's lifecycle?
What occurs if there was previously saved state during the activity's lifecycle?
What is the main purpose of the onPause() method in an Activity's lifecycle?
What is the main purpose of the onPause() method in an Activity's lifecycle?
When is the onPause() method called?
When is the onPause() method called?
What must be ensured for implementations of the onPause() method?
What must be ensured for implementations of the onPause() method?
What happens after the onPause() method is executed if the Activity becomes invisible?
What happens after the onPause() method is executed if the Activity becomes invisible?
What is the purpose of the onStop() method?
What is the purpose of the onStop() method?
Which method follows onStop() if the Activity returns to interact with the user?
Which method follows onStop() if the Activity returns to interact with the user?
What does the onPause() method imply about the Activity's visibility?
What does the onPause() method imply about the Activity's visibility?
What is a common operation to perform in onPause()?
What is a common operation to perform in onPause()?
What types of data does the system save automatically?
What types of data does the system save automatically?
What method must be implemented to save the instance state for an Activity?
What method must be implemented to save the instance state for an Activity?
When is onSaveInstanceState() called by the Android runtime?
When is onSaveInstanceState() called by the Android runtime?
What is the parameter passed to onSaveInstanceState() intended for?
What is the parameter passed to onSaveInstanceState() intended for?
What should developers save in addition to what the system saves?
What should developers save in addition to what the system saves?
How can developers store a counter value in the onSaveInstanceState() method?
How can developers store a counter value in the onSaveInstanceState() method?
What does the Intent data include when saving state?
What does the Intent data include when saving state?
What is the result of not overriding onSaveInstanceState() in an Activity?
What is the result of not overriding onSaveInstanceState() in an Activity?
What happens when the onStop() method is called in an Activity?
What happens when the onStop() method is called in an Activity?
When is the onDestroy() method typically called in an Android Activity?
When is the onDestroy() method typically called in an Android Activity?
What is the purpose of the isFinishing() method in an Activity?
What is the purpose of the isFinishing() method in an Activity?
What does 'Activity instance state' refer to?
What does 'Activity instance state' refer to?
What happens to the Activity's UI state during a configuration change by default?
What happens to the Activity's UI state during a configuration change by default?
Which lifecycle method is called last before an Activity is destroyed?
Which lifecycle method is called last before an Activity is destroyed?
What action typically triggers the onStop() method?
What action typically triggers the onStop() method?
What should you expect in terms of user experience during configuration changes?
What should you expect in terms of user experience during configuration changes?
Flashcards
Activity Lifecycle
Activity Lifecycle
The complete sequence of states an Activity can be in throughout its lifespan, from creation to destruction.
Activity Lifecycle Graph
Activity Lifecycle Graph
A visual representation of the various states an Activity can occupy, along with the corresponding callbacks triggered when transitioning between these states.
Created
Created
A state where the Activity is being created, but is not yet visible to the user.
Stopped
Stopped
Signup and view all the flashcards
onCreate()
onCreate()
Signup and view all the flashcards
onStart()
onStart()
Signup and view all the flashcards
onRestart()
onRestart()
Signup and view all the flashcards
onResume()
onResume()
Signup and view all the flashcards
onPause()
onPause()
Signup and view all the flashcards
Created State
Created State
Signup and view all the flashcards
Started State
Started State
Signup and view all the flashcards
onSaveInstanceState()
onSaveInstanceState()
Signup and view all the flashcards
Saved Instance State
Saved Instance State
Signup and view all the flashcards
onRestoreInstanceState()
onRestoreInstanceState()
Signup and view all the flashcards
onStop()
onStop()
Signup and view all the flashcards
onStop() vs onPause() performance
onStop() vs onPause() performance
Signup and view all the flashcards
onDestroy()
onDestroy()
Signup and view all the flashcards
onRestart() and back navigation
onRestart() and back navigation
Signup and view all the flashcards
Why is onPause() fast?
Why is onPause() fast?
Signup and view all the flashcards
What does the system save automatically?
What does the system save automatically?
Signup and view all the flashcards
What data are you responsible for saving?
What data are you responsible for saving?
Signup and view all the flashcards
What is onSaveInstanceState()?
What is onSaveInstanceState()?
Signup and view all the flashcards
What argument does onSaveInstanceState() receive?
What argument does onSaveInstanceState() receive?
Signup and view all the flashcards
How do you save data using onSaveInstanceState()?
How do you save data using onSaveInstanceState()?
Signup and view all the flashcards
How is data retrieved when the Activity is restored?
How is data retrieved when the Activity is restored?
Signup and view all the flashcards
How does the system restore the Activity's state?
How does the system restore the Activity's state?
Signup and view all the flashcards
What mechanism does the system utilize to restore an Activity's state?
What mechanism does the system utilize to restore an Activity's state?
Signup and view all the flashcards
Activity Instance State
Activity Instance State
Signup and view all the flashcards
isFinishing()
isFinishing()
Signup and view all the flashcards
Configuration Change
Configuration Change
Signup and view all the flashcards
Study Notes
Android Developer Fundamentals V2 - Activities (Chapter 6)
- Activities: A fundamental building block of Android apps, representing screens or interactive portions of an application.
- Activity Lifecycle: The sequence of states an Activity goes through during its lifetime, from creation to destruction. This includes key events and callbacks associated with each state transition.
- States: Various states an Activity occupies throughout its lifecycle, including Created, Started, Resumed, Paused, Stopped, and Destroyed.
Activity Lifecycle Callbacks
- onCreate(): Initiates Activity initialization, typically performing static setup, such as view creation and data binding. Occurs only once.
- onStart(): Marks the beginning of Activity visibility and interaction with the user. It is possible for this to be called multiple times.
- onRestart(): Called if the Activity has been stopped then restarted from another Activity. A transient phase leading back to the onStart() state.
- onResume(): Activity is now fully visible and active, accepting user input and capable of performing UI interactions. Subsequently followed by onPause().
- onPause(): Occurs just before the Activity loses focus, temporarily pauses its functionality, often used to save data or stop animations while another Activity takes precedence.
- onStop(): Activity is completely hidden and not visible to the user. Heavy-duty operations that need not be immediately responsive should be put here. Followed by onRestart() if user returns to this Activity, or onDestroy() if the activity is closed.
- onDestroy(): The activity is about to be destroyed, representing its final callback before disposal by the system. Use for cleanup tasks or releasing resources.
Activity Instance State
- State Information: Data regarding an Activity's UI state, like user input, counter values, animation progression, and other essential properties that the user will anticipate remaining the same.
- State Preservation: Android systems often destroy Activities to conserve memory.
onSaveInstanceState()
andonRestoreInstanceState()
are used to persist this data, thereby ensuring it doesn't get deleted when a configuration change or new activity takes over.
Saving and Restoring Activity State
- System Saves: Android primarily saves basic view data, such as unique ID values and user inputs, but you are responsible for other state information, if persistence is desired across app session restarts.
- onSaveInstanceState(): Implemented within the Activity, this method is called before a potentially imminent Activity destruction event. Key within Activity persistence when configuring the state to be saved. Data is saved within a Bundle(outState) object.
- onRestoreInstanceState(): Called upon a successful restart to retrieve the saved state. Used in conjunction with onSaveInstanceState() to ensure consistent app state on the application's restart.
Assessments (Quizzes, Lab Assignments, Project, Final)
- Assessment 1 (Quiz 1): Completed.
- Assessment 2 (Lab Assignments): Ongoing assignments.
- Assessment 3 (Project): A project comprising a design component (20%) and a report (10%), due 13/01/2025. Separate time slots for Group A and Group B.
- Assessment 4 (Final Assessment): Comprehensive theoretical and programming assessment due on 20/01/2025.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.