/
Android Intent Deep Dive
Save to my account
Sign up
Report Bug
Android Intent Deep Dive
Android Intent Deep Dive
Study
Question
What is the primary purpose of the AndroidManifest.xml file in an Android application?
Answer
The AndroidManifest.xml file is the central file where each activity is declared so that Android can recognize it. It manages the navigation structure and specifies which activities are accessible, including essential parameters like screen orientation and launch modes.
Question
What does the <application> node describe in the AndroidManifest.xml file?
Answer
The <application> node describes the attributes and various components that characterize the application. By default, the application has one main component, the main activity, but it can include multiple components interacting with each other and the system.
Question
What is the role of the <activity> node in the AndroidManifest.xml file?
Answer
The <activity> node describes each activity (or screen) of the application. It includes key attributes like android:name, which indicates the Java class implementing the activity and serves as a unique identifier, and android:label, which defines a visible name displayed at the top of the screen when the activity is open.
Question
What is the purpose of an <intent-filter> in the AndroidManifest.xml file?
Answer
An <intent-filter> specifies how an activity can be launched. For example, the activity launched from the Android main menu contains an intent-filter with Action: MAIN (indicating the entry point) and Category: LAUNCHER (indicating it should appear in the application launcher screen).
Question
What are the essential components of an Intent in Android?
Answer
An Intent contains an Action, describing what the recipient should do (e.g., 'ACTION_VIEW' to display a page), and Data, specifying what data the action applies to (like a URL or phone number). It can also include optional additional fields such as categories, types, extras, and flags to refine its behavior.
Question
How do Categories, Type, Extras, and Flags enhance the functionality of an Intent?
Answer
Categories provide extra details about the action and help identify components that can handle the intent (e.g., CATEGORY_LAUNCHER). Type specifies the format of data included (like image/jpeg). Extras add additional data to pass between components. Flags modify the intent's behavior, such as how it is managed in the activity stack (e.g., FLAG_ACTIVITY_NEW_TASK to start an activity in a new task).
Question
What is the difference between explicit and implicit intents?
Answer
Explicit intents specify the target component's class directly and are mainly used for communication between components within the same app. Implicit intents do not specify a particular target component; instead, they trigger an action that can be handled by multiple applications (e.g., sending an email from your app).
Question
How is an explicit intent generally used in an Android application?
Answer
An explicit intent directly targets a specific component by specifying its context and destination class. It is typically used to start an activity or service within the same application.
Question
How do you start an activity without expecting a return result using an explicit intent in Java?
Answer
You create an Intent specifying the current context and the destination activity class, then call startActivity(intent). For example: Intent intent = new Intent(this, Activity2.class); startActivity(intent); This launches the Activity2 without waiting for a result.
Question
What must be done before starting a new activity using an Intent to avoid an ActivityNotFoundException?
Answer
Before starting a new activity, it must be declared in the AndroidManifest.xml file. Without this declaration, Android will throw an ActivityNotFoundException error when attempting to start the activity.