Podcast
Questions and Answers
Which callback method is invoked only once during the entire lifecycle of an activity?
Which callback method is invoked only once during the entire lifecycle of an activity?
- `onStart()`
- `onResume()`
- `onCreate()` (correct)
- `onPause()`
An activity transitions from the visible state to a state where it is no longer visible. Which callback method is invoked during this transition?
An activity transitions from the visible state to a state where it is no longer visible. Which callback method is invoked during this transition?
- `onStart()`
- `onPause()` (correct)
- `onRestart()`
- `onResume()`
Under what circumstance is the onDestroy()
callback method invoked?
Under what circumstance is the onDestroy()
callback method invoked?
- When the activity is resumed after being stopped.
- When the activity is finishing or being destroyed due to configuration change. (correct)
- When the activity becomes hidden.
- When the activity is initially created.
An activity is currently stopped. Which callback method is invoked if the activity returns to interact with the user?
An activity is currently stopped. Which callback method is invoked if the activity returns to interact with the user?
What role does the back stack play when a new activity starts?
What role does the back stack play when a new activity starts?
Which of the following accurately describes the purpose of an Intent in Android development?
Which of the following accurately describes the purpose of an Intent in Android development?
An Intent needs to pass data to the receiving activity. Which part of the Intent is responsible for carrying this data?
An Intent needs to pass data to the receiving activity. Which part of the Intent is responsible for carrying this data?
How might an Intent, through the use of flags, influence the Android system when launching an activity?
How might an Intent, through the use of flags, influence the Android system when launching an activity?
What differentiates an explicit Intent from an implicit Intent?
What differentiates an explicit Intent from an implicit Intent?
If you want to specify the exact component to handle the Intent, which type of Intent would you use?
If you want to specify the exact component to handle the Intent, which type of Intent would you use?
How do you programmatically set up navigation between two activities using explicit Intents?
How do you programmatically set up navigation between two activities using explicit Intents?
What is the significance of the parentActivityName
attribute in the <activity>
element of the AndroidManifest.xml
file?
What is the significance of the parentActivityName
attribute in the <activity>
element of the AndroidManifest.xml
file?
In the context of Android activities, what does the term "activity lifecycle" refer to?
In the context of Android activities, what does the term "activity lifecycle" refer to?
Consider an activity that is currently visible and running in the foreground. If a phone call interrupts the user, which callback method is MOST likely to be invoked first?
Consider an activity that is currently visible and running in the foreground. If a phone call interrupts the user, which callback method is MOST likely to be invoked first?
What is the primary purpose of calling super.onCreate(savedInstanceState)
within the onCreate()
method of an Activity?
What is the primary purpose of calling super.onCreate(savedInstanceState)
within the onCreate()
method of an Activity?
In the code snippet android:onClick="launchNextActivity"
, what does launchNextActivity
refer to?
In the code snippet android:onClick="launchNextActivity"
, what does launchNextActivity
refer to?
If a user rotates their device, what is the typical behavior of an Android activity, and which lifecycle methods are involved?
If a user rotates their device, what is the typical behavior of an Android activity, and which lifecycle methods are involved?
To display a user interface for an activity, which method is commonly used and what parameter does it take?
To display a user interface for an activity, which method is commonly used and what parameter does it take?
Which combination of steps is required to properly implement a new Activity in an Android application?
Which combination of steps is required to properly implement a new Activity in an Android application?
What purpose does Toast.makeText(getApplicationContext(), "New activity launched!", Toast.LENGTH_SHORT).show();
serve in verifying Intent functionality?
What purpose does Toast.makeText(getApplicationContext(), "New activity launched!", Toast.LENGTH_SHORT).show();
serve in verifying Intent functionality?
Flashcards
Activity (in Android)
Activity (in Android)
Represents a single screen in an app for a focused task, usually full-screen.
onCreate()
onCreate()
Called when the app is launched; happens only once per the activity's life.
onStart()
onStart()
Called before the activity becomes visible to the user.
onResume()
onResume()
Signup and view all the flashcards
onPause()
onPause()
Signup and view all the flashcards
onStop()
onStop()
Signup and view all the flashcards
onDestroy()
onDestroy()
Signup and view all the flashcards
onRestart()
onRestart()
Signup and view all the flashcards
Back Stack
Back Stack
Signup and view all the flashcards
Intent (in Android)
Intent (in Android)
Signup and view all the flashcards
Target Activity
Target Activity
Signup and view all the flashcards
Intent Data/Object
Intent Data/Object
Signup and view all the flashcards
Intent Extras
Intent Extras
Signup and view all the flashcards
Intent Flags
Intent Flags
Signup and view all the flashcards
Explicit Intent
Explicit Intent
Signup and view all the flashcards
Implicit Intent
Implicit Intent
Signup and view all the flashcards
parentActivityName
parentActivityName
Signup and view all the flashcards
Study Notes
- Represents a single screen in an app where a user does tasks like sending email
- Usually shown to the user as a full-screen window
Activity Implementation
- First, create an Activity Java class
- Next, implement a basic UI for the Activity in an associated XML layout file
- Finally, declare the new Activity in AndroidManifest.xml
- To automate these tasks in Android Studio, use File > New > Activity to start from a template
- MainActivity.java is presented to the user when the app launches and can start other activities
Activity Life Cycle
- The set of states an activity can be in during its entire lifetime
- The callback methods used during the activity lifecycle include: onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(), and onRestart()
Callback Methods
- onCreate() is invoked when the app launches for the first time, only once for the entire lifespan
- onStart() is invoked before the activity is visible, followed by onResume() if it comes to the foreground, or onStop() if it becomes hidden
- onResume() is invoked before the activity starts interacting with the user
- onPause() is invoked when the system is about to start resuming another activity, followed by onResume() if the activity returns to the background, or onStop() if it becomes invisible
- onStop() is invoked when the activity is no longer visible, followed by onRestart() if the activity is coming back to interact with the user, or onDestroy() if the activity is about to end
- onDestroy() is invoked when the activity is finishing because the user is completely dismissing it, or the system is temporarily destroying the activity due to a configuration change
- onRestart() is invoked if the activity comes back after being stopped and is always followed by onStart()
- Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in the back stack
Intents
- An Intent is an asynchronous message used in an activity to request an action from another activity or app component
- Intents can start activities and pass data
Intent Parts
- Target activity - the activity receiving the intent
- Intent data/object - reference to data for the receiving activity
- Intent extras - carries information for the receiving activity (optional)
- Intent flags - instructs the system how to launch or treat the activity (optional)
Intent Types
- Explicit intent's target (activity class name) is already identified
- Implicit intent's target is not yet identified, but there is a general action to perform, including action, category, and data type
- The parentActivityName attribute indicates the main activity is the parent of the second activity and enables a left-facing arrow for navigation
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.