0

I recently started android. I came across the putExtra(key,value) method in the Intent class. I don't understand what is the use of key parameter.

I want to pass string value to the other activity. Please help me to exoplain the code. I am using from Android Developer Portal.

Nilanchala
  • 5,891
  • 8
  • 42
  • 72
mik dass
  • 381
  • 3
  • 16

1 Answers1

0

Key is used to retrieve data from the second Activity. For example, in the following code snippet you are using YOUR_KEY as a string while sending data along with intent bundle.

Intent intent = new Intent(this, Activity2.class);
String message = editText.getText().toString();
intent.putExtra("YOUR_KEY", message);
startActivity(intent);

In Activity2, you can retrieve the values using

String message = intent.getStringExtra("YOUR_KEY");
Nilanchala
  • 5,891
  • 8
  • 42
  • 72