Android Developer Fundamentals V2 - Activities
42 Questions
0 Views

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

    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

    Description

    Test your knowledge on Activities in Android applications with this quiz based on Chapter 6 of the Android Developer Fundamentals V2. Learn about the Activity lifecycle, states, and key callbacks that define the behavior and functionality of Activities throughout their lifetime.

    More Like This

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

    Android App Components Quiz

    BetterKnownConnemara9267 avatar
    BetterKnownConnemara9267
    Use Quizgecko on...
    Browser
    Browser