Difficulty: Easy
Correct Answer: By constructing an explicit Intent specifying the current Context and target Activity class, then calling startActivity or startActivityForResult.
Explanation:
Introduction / Context:
Launching Activities is one of the most common tasks in Android. This question checks whether you understand the correct pattern for starting another Activity using an explicit Intent. Knowing this mechanism is basic but vital for implementing navigation within an application, such as moving from a list screen to a detail screen.
Given Data / Assumptions:
Concept / Approach:
Explicit Intents identify the exact component that should handle the Intent. In Android, you typically construct such an Intent with the current Context and the class object of the target Activity. Then you call startActivity to launch it. If you expect a result back, you can call startActivityForResult in older APIs or register a result launcher with the Activity Result API in newer code. The operating system manages the Activity stack and calls life cycle methods accordingly.
Step-by-Step Solution:
Step 1: Ensure that the target Activity is declared in the manifest so that the system is aware of it.Step 2: From the current Activity, create a new Intent object, passing the current Activity as the Context and the target Activity class.Step 3: If no result is needed, call startActivity with this Intent. If a result is needed, use startActivityForResult or the modern Activity Result APIs.Step 4: The system creates the target Activity, calls its life cycle methods, and places it on top of the back stack.Step 5: This standard approach matches the description given in option A.
Verification / Alternative check:
Official Android tutorials and templates consistently demonstrate navigation between Activities using explicit Intents with startActivity. No official example uses running an Activity by calling run or editing the manifest at runtime. Looking at sample projects further confirms that option A describes the correct mechanism.
Why Other Options Are Wrong:
Option B is wrong because Activities are managed by the framework; you do not instantiate them manually and call run. Option C is incorrect since the manifest is static and cannot be edited at runtime to change navigation behavior. Option D is clearly wrong as sending SMS messages is unrelated to Activity management and would pose serious security concerns if it were allowed to control the Activity stack.
Common Pitfalls:
Developers sometimes forget to declare the target Activity in the manifest, which results in runtime exceptions. Another pitfall is misusing the application Context instead of the Activity Context when launching user interface components, which can cause issues with animations or window flags. Following the standard explicit Intent pattern helps avoid these problems.
Final Answer:
By constructing an explicit Intent specifying the current Context and target Activity class, then calling startActivity or startActivityForResult.
Discussion & Comments