102k views
4 votes
If you want to pass data to the receiver, what method of the Intent class can you use to store data in the Intent object?

User NIrav Modi
by
8.1k points

1 Answer

5 votes

Final answer:

To store data in the Intent object and pass it to the receiver, you can use the putExtra method of the Intent class.

Step-by-step explanation:

To store data in the Intent object and pass it to the receiver, you can use the putExtra method of the Intent class. This method allows you to add extra data to the intent using a key-value pair.

Here is an example:

Intent intent = new Intent(context, ReceiverActivity.class);
intent.putExtra("key", "value");

In this example, the "key" is the identifier for the data and "value" is the actual data you want to pass.

If you wish to pass data to the receiver using an Intent in Android development, you can use putExtra() methods of the Intent class to store data. These key-value pairs are known as extras, which the receiving component can then retrieve.

For instance, if you want to pass a string, you would use intent.putExtra("key", "value"). For integers, it would look like intent.putExtra("key", 1). It's also important to use the corresponding get methods to retrieve the data in the receiving Activity or Service. For example, getStringExtra("key") is used to retrieve a string value.

User Ivan R
by
8.1k points