178k views
5 votes
In an activity, which statement can you use to get the intent that started the activity and retrieve a string named title that has been stored in that intent?

A. Intent intent = getIntent(); String title = intent.getStringExtra("title");
B. Intent titleIntent = getIntent("title"); String title = titleIntent.getExtra();
C. String title = getIntent().getStringExtra("title");
D. String title = getIntent("title").getStringExtra();

1 Answer

4 votes

Final answer:

In Android programming, to retrieve a string named 'title' from the intent that started an activity, option C is correct, using getIntent().getStringExtra("title") method to extract the string value.

Step-by-step explanation:

In an Android programming context, to get the intent which started the activity and to retrieve a string named title from that intent, you would use the following code:

String title = getIntent().getStringExtra("title");

This corresponds to option C.

The getIntent() method is called to retrieve the Intent that started the activity.

Then, getStringExtra() is called with the key parameter ("title" in this case) to retrieve the string associated with that key.

User Nicktruesdale
by
7.7k points