Build an intent
An Intent is an object that provides runtime binding between separate components, such as two activities. The Intent represents an app’s intent to do something. You can use intents for a wide variety of tasks, but in this lesson, your intent starts another activity.
In MainActivity, add the EXTRA_MESSAGE constant and the sendMessage() code, as shown:
JAVA:
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user taps the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
Kotlin:
const val EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
/** Called when the user taps the Send button */
fun sendMessage(view: View) {
val editText = findViewById<EditText>(R.id.editText)
val message = editText.text.toString()
val intent = Intent(this, DisplayMessageActivity::class.java).apply {
putExtra(EXTRA_MESSAGE, message)
}
startActivity(intent)
}
}
Better than expected, satisfied, like very much
I used to be able to find good info from your articles. Taryn Godart Brear
Learning curve hypotheses prototype early adopters focus channels direct mailing business-to-business vesting period. Equity seed round funding advisor partnership vesting period channels niche market social media business plan long tail. Startup deployment partner network holy grail pivot bootstrapping product management accelerator virality churn rate business-to-consumer network effects seed round. Influencer client startup. Maddi Kipp Zalucki
Whilst fans are focused on the NCAA basketball championships, the FBI continues to combat criminal activity in the sports
industry.
If some one desires to be updated with newest technologies then he must be go to see this web site and be up to date daily.
Hey! Someone in my Myspace group shared this site with
us so I came to give it a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers!
Superb blog and terrific design.
Excellent blog here! Also your website loads up fast!
What web host are you using? Can I get your affiliate link to your host?
I wish my site loaded up as quickly as yours lol
Fantastic web site. A lot of helpful information here. I’m
sending it to several friends ans also sharing in delicious.
And naturally, thank you to your effort!