Sobes.tech
Junior — Middle

How can data be passed when launching a new screen in an Android app?

sobes.tech AI

Answer from AI

In Android, data transfer when launching a new screen (Activity) is done using an Intent object. Additional data can be put into the Intent using putExtra(), and retrieved in the new Activity via getIntent().

Example of data transfer:

Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
intent.putExtra("key", "value");
startActivity(intent);

In the new Activity:

String value = getIntent().getStringExtra("key");

Thus, strings, numbers, objects implementing Parcelable or Serializable, and other data types can be transferred between screens.

How can data be passed when launching a new screen in… - sobes.tech