Podcast
Questions and Answers
What is the primary purpose of an Activity in an Android app?
What is the primary purpose of an Activity in an Android app?
Which component is used to pass information between applications?
Which component is used to pass information between applications?
What happens when an Activity uses too many resources?
What happens when an Activity uses too many resources?
What is the purpose of a Broadcast Receiver?
What is the purpose of a Broadcast Receiver?
Signup and view all the answers
What is the purpose of a Content Provider?
What is the purpose of a Content Provider?
Signup and view all the answers
What happens when the user presses the Back button or destroys Activity 1?
What happens when the user presses the Back button or destroys Activity 1?
Signup and view all the answers
What is the purpose of a Service?
What is the purpose of a Service?
Signup and view all the answers
What is the Activity Stack?
What is the Activity Stack?
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?
What is the primary state of an activity when it is completely hidden and not visible to the user?
Signup and view all the answers
What happens if an app starts an activity that is not declared in the AndroidManifest.xml file?
What happens if an app starts an activity that is not declared in the AndroidManifest.xml file?
Signup and view all the answers
What is the purpose of the onCreate() and onDestroy() methods in the activity lifecycle?
What is the purpose of the onCreate() and onDestroy() methods in the activity lifecycle?
Signup and view all the answers
What is the purpose of the onStart() and onStop() methods in the activity lifecycle?
What is the purpose of the onStart() and onStop() methods in the activity lifecycle?
Signup and view all the answers
What is the purpose of the onResume() and onPause() methods in the activity lifecycle?
What is the purpose of the onResume() and onPause() methods in the activity lifecycle?
Signup and view all the answers
What is the purpose of logging in an activity?
What is the purpose of logging in an activity?
Signup and view all the answers
What is the purpose of creating a TAG when logging in an activity?
What is the purpose of creating a TAG when logging in an activity?
Signup and view all the answers
What is an important consideration when overriding activity lifecycle methods?
What is an important consideration when overriding activity lifecycle methods?
Signup and view all the answers
What is the primary purpose of using Logcat in an Android app?
What is the primary purpose of using Logcat in an Android app?
Signup and view all the answers
What should you do when an activity is paused?
What should you do when an activity is paused?
Signup and view all the answers
What happens to an activity when the user receives a phone call?
What happens to an activity when the user receives a phone call?
Signup and view all the answers
Why should you not explicitly finish an activity?
Why should you not explicitly finish an activity?
Signup and view all the answers
What should you do in the onStop() method?
What should you do in the onStop() method?
Signup and view all the answers
What happens when the user opens the Recent Apps window and starts a new application?
What happens when the user opens the Recent Apps window and starts a new application?
Signup and view all the answers
Why should you stop audio and video in the onPause() method?
Why should you stop audio and video in the onPause() method?
Signup and view all the answers
What is the purpose of the onPause() method?
What is the purpose of the onPause() method?
Signup and view all the answers
What happens to the state of an activity when it is paused or stopped?
What happens to the state of an activity when it is paused or stopped?
Signup and view all the answers
What method can be used to save information when an activity is destroyed?
What method can be used to save information when an activity is destroyed?
Signup and view all the answers
What is the purpose of the Bundle class in Android?
What is the purpose of the Bundle class in Android?
Signup and view all the answers
What happens when an activity is destroyed to recover resources?
What happens when an activity is destroyed to recover resources?
Signup and view all the answers
What is the purpose of the onRestoreInstanceState method?
What is the purpose of the onRestoreInstanceState method?
Signup and view all the answers
When should you save and restore state in an Android app?
When should you save and restore state in an Android app?
Signup and view all the answers
What happens to the onPauseCounter when an app is rotated?
What happens to the onPauseCounter when an app is rotated?
Signup and view all the answers
When is the onSaveInstanceState method called?
When is the onSaveInstanceState method called?
Signup and view all the answers
What is the purpose of startActivityForResult?
What is the purpose of startActivityForResult?
Signup and view all the answers
What is the purpose of the onPause method in the activity lifecycle?
What is the purpose of the onPause method in the activity lifecycle?
Signup and view all the answers
What happens if an Activity does not clean up after itself?
What happens if an Activity does not clean up after itself?
Signup and view all the answers
What is the purpose of setResult()?
What is the purpose of setResult()?
Signup and view all the answers
What is the purpose of an Intent in an Android app?
What is the purpose of an Intent in an Android app?
Signup and view all the answers
What should you do when you start a new Activity?
What should you do when you start a new Activity?
Signup and view all the answers
What is the purpose of override onRestoreInstanceState?
What is the purpose of override onRestoreInstanceState?
Signup and view all the answers
What is the purpose of onActivityResult()?
What is the purpose of onActivityResult()?
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.
Related Documents
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.