CS371m: Anatomy of an Android App
40 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 is the primary purpose of an Activity in an Android app?

  • To perform long-running operations in the background with no UI
  • To respond to system-wide announcements
  • To provide a single screen with a user interface (correct)
  • To share data between applications
  • Which component is used to pass information between applications?

  • Service
  • Intent (correct)
  • Broadcast Receiver
  • Content Provider
  • What happens when an Activity uses too many resources?

  • It is resumed
  • It is paused
  • It is destroyed (correct)
  • It is brought to the top of the Activity Stack
  • What is the purpose of a Broadcast Receiver?

    <p>To respond to system-wide announcements</p> Signup and view all the answers

    What is the purpose of a Content Provider?

    <p>To share data between applications</p> Signup and view all the answers

    What happens when the user presses the Back button or destroys Activity 1?

    <p>Activity 2 is brought to the top</p> Signup and view all the answers

    What is the purpose of a Service?

    <p>To perform long-running operations in the background with no UI</p> Signup and view all the answers

    What is the Activity Stack?

    <p>A stack of activities</p> Signup and view all the answers

    What is the primary state of an activity when it is completely hidden and not visible to the user?

    <p>Stopped</p> Signup and view all the answers

    What happens if an app starts an activity that is not declared in the AndroidManifest.xml file?

    <p>A runtime error occurs</p> Signup and view all the answers

    What is the purpose of the onCreate() and onDestroy() methods in the activity lifecycle?

    <p>To load and unload UI components</p> Signup and view all the answers

    What is the purpose of the onStart() and onStop() methods in the activity lifecycle?

    <p>To access or release resources that influence UI</p> Signup and view all the answers

    What is the purpose of the onResume() and onPause() methods in the activity lifecycle?

    <p>To start and stop audio, video, animations</p> Signup and view all the answers

    What is the purpose of logging in an activity?

    <p>To log activity lifecycle methods</p> Signup and view all the answers

    What is the purpose of creating a TAG when logging in an activity?

    <p>To filter log messages</p> Signup and view all the answers

    What is an important consideration when overriding activity lifecycle methods?

    <p>Always call the parent method first</p> Signup and view all the answers

    What is the primary purpose of using Logcat in an Android app?

    <p>To debug and diagnose issues in the app</p> Signup and view all the answers

    What should you do when an activity is paused?

    <p>Stop animations and CPU-intensive tasks</p> Signup and view all the answers

    What happens to an activity when the user receives a phone call?

    <p>The activity is stopped</p> Signup and view all the answers

    Why should you not explicitly finish an activity?

    <p>Because the system manages the life of an activity</p> Signup and view all the answers

    What should you do in the onStop() method?

    <p>Release all resources and save information</p> Signup and view all the answers

    What happens when the user opens the Recent Apps window and starts a new application?

    <p>The current activity is stopped</p> Signup and view all the answers

    Why should you stop audio and video in the onPause() method?

    <p>To release system resources</p> Signup and view all the answers

    What is the purpose of the onPause() method?

    <p>To release resources and stop CPU-intensive tasks</p> Signup and view all the answers

    What happens to the state of an activity when it is paused or stopped?

    <p>The activity's state is retained</p> Signup and view all the answers

    What method can be used to save information when an activity is destroyed?

    <p>onSaveInstanceState</p> Signup and view all the answers

    What is the purpose of the Bundle class in Android?

    <p>To store data in a map</p> Signup and view all the answers

    What happens when an activity is destroyed to recover resources?

    <p>The system calls the onSaveInstanceState method</p> Signup and view all the answers

    What is the purpose of the onRestoreInstanceState method?

    <p>To restore the activity's state</p> Signup and view all the answers

    When should you save and restore state in an Android app?

    <p>In onSaveInstanceState</p> Signup and view all the answers

    What happens to the onPauseCounter when an app is rotated?

    <p>It is retained</p> Signup and view all the answers

    When is the onSaveInstanceState method called?

    <p>When the activity is destroyed</p> Signup and view all the answers

    What is the purpose of startActivityForResult?

    <p>To get a result from a new Activity</p> Signup and view all the answers

    What is the purpose of the onPause method in the activity lifecycle?

    <p>To pause the activity</p> Signup and view all the answers

    What happens if an Activity does not clean up after itself?

    <p>The MediaPlayer will keep playing even after the Activity is destroyed</p> Signup and view all the answers

    What is the purpose of setResult()?

    <p>To set the result of an Activity</p> Signup and view all the answers

    What is the purpose of an Intent in an Android app?

    <p>To start a new Activity</p> Signup and view all the answers

    What should you do when you start a new Activity?

    <p>All of the above</p> Signup and view all the answers

    What is the purpose of override onRestoreInstanceState?

    <p>To restore the state of an Activity</p> Signup and view all the answers

    What is the purpose of onActivityResult()?

    <p>To get a result from a new Activity</p> Signup and view all the answers

    Study Notes

    Anatomy of an Android App and the App Lifecycle

    • An Android app has four primary components: Activities, Services, Content Providers, and Broadcast Receivers, each with different purposes and lifecycles.

    Application Components

    • Activity: a single screen with a user interface, app may have several activities, subclass of Activity.
    • Service: an application component that performs long-running operations in the background with no UI.
    • Content Provider: a bridge between applications to share data, e.g., device's contacts information.
    • Broadcast Receiver: a component that responds to system-wide announcements, e.g., battery low, screen off, date changed.

    Activity Stack

    • The most recently created Activity is at the top of the stack.
    • When the user presses the Back or the Activity is destroyed, the previous Activity comes to the top.

    Primary States of an Activity

    • Active: the Activity is in the foreground and the user can interact with it.
    • Paused: the Activity is partially obscured by another Activity and the user cannot interact with it.
    • Stopped: the Activity is completely hidden and not visible to the user, but the instance and variables are retained.
    • Dead: the Activity is terminated (or never started).

    Intents

    • Used to pass information between applications.

    AndroidManifest.xml

    • All Activities that are part of the application must be registered in the Manifest.
    • Specify the Activity to start with.

    Purpose of Lifecycle Phases

    • Entire lifetime: onCreate / onDestroy (load UI, start/stop threads).
    • Visible lifetime: onStart / onStop (access/release resources that influence UI, write info to files if necessary).
    • Foreground lifetime: onResume / onPause (restore/save state, start/stop audio/video/animations).

    Activity Lifecycle App

    • Overload methods from Activity: onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), onDestroy().
    • Use the Log class to log activity methods: v, d, i, w, e (VERBOSE, DEBUG, INFO, WARN, ERROR).
    • Create a TAG to filter logs.

    Pausing and Stopping

    • Pausing: onPause method, stop animations, release resources, stop audio/video.
    • Stopping: onStop method, release all resources, save information (persistence).

    Saving State

    • Activities that are paused or stopped retain their state (instance vars).
    • onSaveInstanceState method: save information to a Bundle, which is given back when restarted.

    Activity Destruction

    • App may be destroyed under normal circumstances (finish or back button).
    • onSaveInstanceState method called to save state.
    • System calls onRestoreInstanceState method to recreate the Activity.

    Starting Your Own Activities

    • Start a new Activity to accomplish a task or get some data.
    • Use an Intent, startActivityForResult, and onActivityResult to get a result.

    Intent Demo

    • Intent holding a constant.
    • startActivityForResult and onActivityResult.
    • setResult and finish.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    4_AppAnatomy.pdf

    Description

    Learn about the components of an Android app, including the App Lifecycle, activities, services, and more. Understand the purpose and lifecycle of each component.

    More Like This

    Android App Development Quiz
    48 questions

    Android App Development Quiz

    LionheartedWisdom4273 avatar
    LionheartedWisdom4273
    Android App Development and Prototyping
    100 questions
    Android App Development Basics
    9 questions
    w5ch10
    200 questions

    w5ch10

    ProdigiousQuantum avatar
    ProdigiousQuantum
    Use Quizgecko on...
    Browser
    Browser