Suppose we are sending a data received from text-box from an activity Main\_Activity to another activity Display\_Message\_Activity by clicking a button.

In Main\_Activity:
Step-1: To declare the final String

```
public final static String EXTRA_MESSAGE="com.example.myfirstapp.MESSAGE";

```

Step-2: To assign the click to the button

```
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}

```

Step-3: In DisplayMessageActivity, 

```
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

// Set the text view as the activity layout
setContentView(textView);
}

```

Now my Question is why should we use **intent.getStringExtra(MainActivity.EXTRA\_MESSAGE);** ??
Instead of that, we can easily update the value of static String **MainActivity.EXTRA\_MESSAGE** on button click and then directly access it and assign the value of EXTRA\_MESSAGE string to the \**message* String in DisplayMessageActivity. 
I mean,
step:1

```
 public static String EXTRA_MESSAGE="com.example.myfirstapp.MESSAGE";

```

step:2

```
 public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
EXTRA_MESSAGE=message;
startActivity(intent);
}

```

step:3

```
.
.
.
String message=MainActivity.EXTRA_MESSAGE;
.
.
.

```

Then why usage of Intent is preferred in case of message passing?