Android Application Development (AND-401) — Question 67
Which of the following lines of code starts activity Activity2 from a current activity Activity1?
Answer options
- A. Intent intent = new Intent(this,new Activity2()); startActivity(intent);
- B. Intent intent = new Intent(new Activity2()); startActivity(intent);
- C. Intent intent = new Intent (Activity1.class,Activity2.class); startActivity(intent);
- D. Intent intent = new Intent(this,Activity2.class);
Correct answer: D
Explanation
The correct answer is D because it correctly creates an Intent using the current context and the class of Activity2. Option A incorrectly tries to instantiate Activity2 directly, while B does not provide the current context. Option C incorrectly uses the class references for both activities, which is not the standard way to start an activity.