Im having some doubts with this code.
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
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);
- Why we are using casting in EditText
- What is putExtra(EXTRA_MESSAGE,message) and its use??
- Why is MY_MESSAGE assigned to com.example.myfirstapp.MESSAGE? and What is com.example.myfirstapp.MESSAGE?
1) Because
findViewById()is a generic method which returns a View2) An intent is a flexible way for decoupled communication, it’s like a message that you send (specifying a desired action and optional extra data).
putExtra()is a method that allows you to embed information into your intent3) Intent’s extra data is based on a key-value storage. EXTRA_MESSAGE is the key where your message is stored. The receiver of your intent knows that it can retrieve your message from this key.
4) “com.example.myfirstapp.MESSAGE” is the actual value of this key. It’s an arbitrary value which has to be known by the sender of the intent and its receiver so that they communicate through the intent