Android Developer Fundamentals V2 - Activities

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

  • Paused (correct)
  • Created
  • Stopped
  • Resumed

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?

<p>Initialized (A)</p> Signup and view all the answers

Which state signifies that the Activity is currently active and in the foreground?

<p>Resumed (D)</p> Signup and view all the answers

What happens during the onCreate() callback in an Android Activity lifecycle?

<p>Static initialization and setup occur. (B)</p> Signup and view all the answers

Which callback is triggered when an Activity is no longer visible to the user?

<p>onStop() (C)</p> Signup and view all the answers

During which callback would an Activity start to interact with the user after being obscured?

<p>onResume() (D)</p> Signup and view all the answers

What occurs in the onPause() callback of an Activity lifecycle?

<p>The previous Activity is about to resume. (B)</p> Signup and view all the answers

What function does the onRestart() callback serve in the Android Activity lifecycle?

<p>It is called when returning from stopped state to start state. (D)</p> Signup and view all the answers

What method is called only once during the lifecycle of an activity?

<p>onCreate() (D)</p> Signup and view all the answers

Which method is called immediately after onCreate()?

<p>onStart() (A)</p> Signup and view all the answers

What is the purpose of the Bundle parameter in onCreate()?

<p>To save the activity state for restoration (C)</p> Signup and view all the answers

How many times can the onStart() method be called during an activity's lifecycle?

<p>Multiple times (A)</p> Signup and view all the answers

Which of the following statements about the activity lifecycle is true?

<p>onStart() indicates the activity is becoming visible. (D)</p> Signup and view all the answers

Which lifecycle method is primarily responsible for finalizing the creation of the activity?

<p>onCreate() (B)</p> Signup and view all the answers

What should you expect immediately after the onCreate() method is executed?

<p>The onStart() method is called. (D)</p> Signup and view all the answers

What occurs if there was previously saved state during the activity's lifecycle?

<p>The saved state is restored. (A)</p> Signup and view all the answers

What is the main purpose of the onPause() method in an Activity's lifecycle?

<p>To commit unsaved changes and release resources. (C)</p> Signup and view all the answers

When is the onPause() method called?

<p>When the system is about to resume a previous Activity. (C)</p> Signup and view all the answers

What must be ensured for implementations of the onPause() method?

<p>They must be fast in execution. (C)</p> Signup and view all the answers

What happens after the onPause() method is executed if the Activity becomes invisible?

<p>The onStop() method is called. (C)</p> Signup and view all the answers

What is the purpose of the onStop() method?

<p>To manage heavy-weight operations and resource release. (A)</p> Signup and view all the answers

Which method follows onStop() if the Activity returns to interact with the user?

<p>onRestart() (B)</p> Signup and view all the answers

What does the onPause() method imply about the Activity's visibility?

<p>The Activity is still partly visible. (B)</p> Signup and view all the answers

What is a common operation to perform in onPause()?

<p>Save user state or progress. (D)</p> Signup and view all the answers

What types of data does the system save automatically?

<p>State of views with unique ID and the initiating Intent (A)</p> Signup and view all the answers

What method must be implemented to save the instance state for an Activity?

<p>onSaveInstanceState() (B)</p> Signup and view all the answers

When is onSaveInstanceState() called by the Android runtime?

<p>When there is a chance of Activity being destroyed (C)</p> Signup and view all the answers

What is the parameter passed to onSaveInstanceState() intended for?

<p>To store information for restoration later (A)</p> Signup and view all the answers

What should developers save in addition to what the system saves?

<p>Activity and user progress data with no unique IDs (B)</p> Signup and view all the answers

How can developers store a counter value in the onSaveInstanceState() method?

<p>By adding it to the outState bundle as a string (A)</p> Signup and view all the answers

What does the Intent data include when saving state?

<p>Extras that were added to the Intent (A)</p> Signup and view all the answers

What is the result of not overriding onSaveInstanceState() in an Activity?

<p>Any unsaved data may be lost upon Activity destruction (C)</p> Signup and view all the answers

What happens when the onStop() method is called in an Activity?

<p>The Activity is no longer visible and is considered 'stopped'. (A)</p> Signup and view all the answers

When is the onDestroy() method typically called in an Android Activity?

<p>When the user navigates back to the previous Activity. (B)</p> Signup and view all the answers

What is the purpose of the isFinishing() method in an Activity?

<p>To ascertain if the Activity is being finished or destroyed. (B)</p> Signup and view all the answers

What does 'Activity instance state' refer to?

<p>State information created while the Activity is running. (C)</p> Signup and view all the answers

What happens to the Activity's UI state during a configuration change by default?

<p>The system destroys the Activity and wipes away its UI state. (D)</p> Signup and view all the answers

Which lifecycle method is called last before an Activity is destroyed?

<p>onDestroy() (A)</p> Signup and view all the answers

What action typically triggers the onStop() method?

<p>The Activity is hidden but not destroyed. (D)</p> Signup and view all the answers

What should you expect in terms of user experience during configuration changes?

<p>The Activity will be destroyed unless state is handled. (D)</p> Signup and view all the answers

Flashcards

Activity Lifecycle

The complete sequence of states an Activity can be in throughout its lifespan, from creation to destruction.

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

A state where the Activity is being created, but is not yet visible to the user.

Stopped

A state where the Activity is visible to the user, but is not in the foreground.

Signup and view all the flashcards

onCreate()

This callback is called when the Activity is first created. It handles static setup like creating views or binding data to lists.

Signup and view all the flashcards

onStart()

This callback is called when the Activity becomes visible to the user, indicating the start of its visual appearance on the screen.

Signup and view all the flashcards

onRestart()

This callback is triggered when the Activity is resumed after being stopped. It essentially restarts the Activity.

Signup and view all the flashcards

onResume()

This callback is called when the Activity is fully active and ready to interact with the user.

Signup and view all the flashcards

onPause()

This callback is called when the Activity is about to be paused, as another Activity takes focus. It's a chance for the Activity to save its state.

Signup and view all the flashcards

Created State

The state in which an activity is created but not yet visible to the user.

Signup and view all the flashcards

Started State

The state in which an Activity is becoming/is visible to the user.

Signup and view all the flashcards

onSaveInstanceState()

The process of saving the state of an Activity. It is called when the Activity is destroyed.

Signup and view all the flashcards

Saved Instance State

A bundle containing data that represents the previous state of an activity. It is used to restore the state of an activity when it is recreated.

Signup and view all the flashcards

onRestoreInstanceState()

The method that restores the state of an activity from a saved instance state.

Signup and view all the flashcards

onStop()

A method that is called when the Activity is no longer visible to the user.

Signup and view all the flashcards

onStop() vs onPause() performance

This method is usually used to perform operations that are too heavy for the onPause() method, like releasing resources or saving data.

Signup and view all the flashcards

onDestroy()

The Activity is being finished and removed from the system. It's the final step of the Activity's lifecycle.

Signup and view all the flashcards

onRestart() and back navigation

When a user navigates back to an Activity, its Activity's life begins at the onRestart method and proceeds following the lifecycle callbacks from there.

Signup and view all the flashcards

Why is onPause() fast?

onPause() should be as fast as possible so the Activity can be quickly resumed.

Signup and view all the flashcards

What does the system save automatically?

The Android system automatically saves the state of views with unique IDs, like text entered in an EditText, and the Intent that started the Activity, along with any data in its extras.

Signup and view all the flashcards

What data are you responsible for saving?

You are responsible for saving any other data related to the Activity or user progress, such as preferences or game scores.

Signup and view all the flashcards

What is onSaveInstanceState()?

A method that is called by the Android runtime when there is a possibility the Activity might be destroyed. It allows you to save data specific to the current instance of the Activity during the current session.

Signup and view all the flashcards

What argument does onSaveInstanceState() receive?

The method onSaveInstanceState() receives a Bundle object as an argument. You can use this Bundle to store data that needs to be saved, such as the state of UI elements.

Signup and view all the flashcards

How do you save data using onSaveInstanceState()?

You can save data to be restored later by putting it in the Bundle object provided by the onSaveInstanceState() method. This data can then be retrieved when the Activity is restored.

Signup and view all the flashcards

How is data retrieved when the Activity is restored?

When the Activity is recreated, the Android runtime passes the saved data from the Bundle back to the Activity using the onRestoreInstanceState() method.

Signup and view all the flashcards

How does the system restore the Activity's state?

If an Activity is destroyed and later recreated, the system can restore its state by calling the onRestoreInstanceState() method with the saved data from the Bundle.

Signup and view all the flashcards

What mechanism does the system utilize to restore an Activity's state?

If an Activity is destroyed and recreated, the system uses the saved data from the Bundle to restore the Activity to its previous state, potentially using information from the saved Bundle.

Signup and view all the flashcards

Activity Instance State

The data that represents the state of an Activity instance, such as user inputs, counter values, or progress indicators, that gets stored and restored when an Activity transitions between different states (e.g., when transitioning to the background).

Signup and view all the flashcards

isFinishing()

This method is used within the onDestroy() callback to check whether an activity is intentionally being finished by the user or system. It is useful for deciding how to handle specific cleanup tasks.

Signup and view all the flashcards

Configuration Change

A UI state change, such as screen orientation change or multi-window mode activation, that can lead to the system destroying and recreating an activity.

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() and onRestoreInstanceState() 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.

Quiz Team

Related Documents

More Like This

Mastering Android Activities
9 questions
Composants d'une application Android
8 questions
Activities and Intents in Android Development
12 questions
Android App Components Quiz
47 questions

Android App Components Quiz

BetterKnownConnemara9267 avatar
BetterKnownConnemara9267
Use Quizgecko on...
Browser
Browser