If your layout didn't turn out as expected, click See the final layout XML below to see what your XML should look like. Compare it to what you see in the Code tab. If your attributes appear in a different order, that's okay.
Expect Android Studio to encounter Cannot resolve symbol errors again. To clear the errors, press Alt+Enter, or Option+Return on a Mac. Your should end up with the following imports:
An error still remains for DisplayMessageActivity, but that's okay. You fix it in the next section.
Here's what's going on in sendMessage():
The
Intentconstructor takes two parameters, aContextand aClass.The
Contextparameter is used first because theActivityclass is a subclass ofContext.The
Classparameter of the app component, to which the system delivers theIntent,is, in this case, the activity to start.The
putExtra()method adds the value ofEditTextto the intent. AnIntentcan carry data types as key-value pairs called extras.Your key is a public constant
EXTRA_MESSAGEbecause the next activity uses the key to retrieve the text value. It's a good practice to define keys for intent extras with your app's package name as a prefix. This ensures that the keys are unique, in case your app interacts with other apps.- The
startActivity()method starts an instance of theDisplayMessageActivitythat's specified by theIntent. Next, you need to create that class.

0 Comments