Podcast
Questions and Answers
Which callback method is called only once during the entire lifecycle of an activity when the application is initially launched?
Which callback method is called only once during the entire lifecycle of an activity when the application is initially launched?
- `onResume()`
- `onStart()`
- `onCreate()` (correct)
- `onPause()`
An activity is no longer visible to the user. Which callback method is invoked, and what are the possible subsequent methods called?
An activity is no longer visible to the user. Which callback method is invoked, and what are the possible subsequent methods called?
- `onStop()`, followed by `onRestart()` or `onDestroy()` (correct)
- `onPause()`, followed by `onResume()` or `onStop()`
- `onResume()`, followed by `onPause()` or `onDestroy()`
- `onDestroy()`, followed by `onCreate()` or `onStart()`
In which scenario is the onDestroy()
method called?
In which scenario is the onDestroy()
method called?
- The activity is temporarily hidden by another activity.
- The activity is finishing due to the user dismissing it or `finish()` being called. (correct)
- The user navigates back to the activity from the background.
- The device orientation changes, but the activity remains visible.
What is the purpose of an Intent in Android development?
What is the purpose of an Intent in Android development?
Which part of an Intent contains a reference to the data that the receiving activity should operate on?
Which part of an Intent contains a reference to the data that the receiving activity should operate on?
What is the key difference between an explicit intent and an implicit intent?
What is the key difference between an explicit intent and an implicit intent?
If you want to enable a left-facing arrow in the action bar that allows the user to navigate back to the parent activity, what attribute should you use in the <activity>
element in the AndroidManifest.xml
file?
If you want to enable a left-facing arrow in the action bar that allows the user to navigate back to the parent activity, what attribute should you use in the <activity>
element in the AndroidManifest.xml
file?
What is the significance of the back stack in the context of Android activities?
What is the significance of the back stack in the context of Android activities?
When an activity transitions from the stopped state back to being visible and interactive, which callback method is invoked immediately before onStart()
?
When an activity transitions from the stopped state back to being visible and interactive, which callback method is invoked immediately before onStart()
?
When using an explicit intent to start another activity, what does the this
keyword represent in the Intent
constructor (e.g., Intent intent = new Intent(this, Main2Activity.class);
)?
When using an explicit intent to start another activity, what does the this
keyword represent in the Intent
constructor (e.g., Intent intent = new Intent(this, Main2Activity.class);
)?
Flashcards
Activity
Activity
A single, focused screen in an app for a specific task, presented full-screen to the user.
onCreate()
onCreate()
Method invoked when the app first launches; happens only once.
onStart()
onStart()
Invoked just 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
Intent
Intent
Signup and view all the flashcards
Explicit intent
Explicit intent
Signup and view all the flashcards
Study Notes
- Activities represent a single screen in an app, allowing users to perform focused tasks, typically presented as a full-screen window
- To implement an activity, create an Activity Java class, implement a basic UI in an associated XML layout file, and declare the new Activity in AndroidManifest.xml
- File > New > Activity in Android Studio can automate these steps to start from a template
Activity Lifecycle
- The activity life cycle is the set of states an activity can be in during its entire lifetime, beginning with creation and ending with destruction.
Callback Methods
-
onCreate() executes only once for the entire life of the activity, when the app is launched for the first time
-
onStart() is invoked before the activity becomes visible to the user, followed by either onResume() if the activity comes to the foreground or onStop() if the activity 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 either onResume() if the activity returns to the background, or onStop() if the activity becomes invisible
-
onStop() is invoked when the activity is no longer visible, followed by either onRestart(), which comes back to interact with the user or onDestroy() if the activity is about to end
-
onDestroy() is invoked when the activity is finishing due to being dismissed by the user, or due to finish() being called or destroyed because the system is temporarily due to a configuration change
-
onRestart() is invoked if the activity comes back after being stopped, and is always followed by onStart()
Intents
- Activities are started or activated with an Intent, which is an asynchronous message, used to request an action from another activity or app component and to pass data
- Parts of an intent include: Target activity, Intent data/object, Intent extras (optional), Intent flags (optional)
Types of Intents
- Explicit Intent: The target of the intent is already identified by class name
- Implicit Intent: The target is not yet identified, requiring a general action, category, and data type
Adding Intents
-
Within AndroidManifest.xml, activity elements can define properties like android:parentActivityName, indicating which activity is the parent enabling a left-facing arrow for navigation
-
To start another activity, add the android:onClick attribute to a Button element in XML, then define the corresponding method, which creates an Intent and starts the new activity
-
Adding a toast message in the launched activity verifies the intent works
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.