In Android development, an Intent is a messaging object you can use to request an action from another app component. Intents are primarily used to start new activities, start services, and deliver broadcasts. This capability allows different components of an application or even different applications to communicate with one another.
There are mainly two types of Intents: explicit intents and implicit intents. Explicit intents specify the component to start by name, whereas implicit intents do not name a specific component and instead declare a general action to perform.
To illustrate the integration of Intents, let's see how to launch an activity with an explicit intent and send data between activities using putExtra()
and retrieve it using getIntent()
.
Here is an example of how to integrate intents in an Android application:
// MainActivity.java
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("EXTRA_MESSAGE", "Hello, Second Activity!");
startActivity(intent);
// SecondActivity.java
Intent intent = getIntent();
String message = intent.getStringExtra("EXTRA_MESSAGE");
TextView textView = findViewById(R.id.textView);
textView.setText(message);
In this example, we create an Intent in MainActivity
to start SecondActivity
. We pass a string extra data using the putExtra()
method. In SecondActivity
, we retrieve the data using getStringExtra()
and display it in a TextView.
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?