Android Application Development (AND-401) — Question 90
Which of the following lines of code is used to pass a value to the next activity?
Answer options
- A. Intent i = new Intent(this,newActivity); i.addExtra("test"); startActivity(i);
- B. Intent i = new Intent(this,newActivity); i.putValue("test"); startActivity(i);
- C. Intent i = new Intent(this,newActivity); i.putValue("value1","test"); startActivity(i);
- D. Intent i = new Intent(this,newActivity); i.putExtra("value1","test");
Correct answer: D
Explanation
The correct answer is D because the method `putExtra` is specifically designed to send additional data to the next activity. Options A, B, and C use incorrect methods (`addExtra` and `putValue`), which do not exist in the Intent class, making them invalid for passing values.