I am new to android development. I am learning android development given here their is a piece of code
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);
I want to know why we use String message = editText.getText().toString() after using EditText editText = (EditText) findViewById(R.id.edit_message); What does EditText return?
Using EditText editText = (EditText) findViewById(R.id.edit_message);
This line registers your xml editText with the class file editText. As you develop an app, the design is done in the xml file and coding is in the .class file.
Somewhere it is working as a Listener, like if you write something in the editText then,
By this line it is notified that the editText is notified.
NOTE: If you do directly
String message = editText.getText().toString()
.without doing thisEditText editText = (EditText) findViewById(R.id.edit_message)
you will get NullPointer Exception.