Using Intent in Android Studio With Extra Data
Article have related YouTube video
For most Android apps it is essential to be able to link between different activities like the anchor tag in HTML. Sometimes you also want to send data from one activity to another. It could be an id or a name.
To link between activities is fortunately simple and straight forward.
Simple Intent
Intent intent = new Intent(MainActivity.this, SecondActivity.class);,
startActivity(intent);
Intent with Extra data
Intent intent = new Intent(MainActivity.this, SecondActivity.class);,
intent.putExtra("extra","This is the extra data");
startActivity(intent);
Recieving the data in SecondActivity
String extraText;
//Check if intent has extra
if (intent.hasExtra("extra")) {
extra = intent.getStringExtra("extra");
} else {
extra = "No extra data";
}