How Will You Get the Data in Second Activity in Android?

How Will You Get the Data in Second Activity in Android?
Contents

We can send the data using putExtra() method from one activity and get the data from the second activity using getStringExtra() methods. Example: In this Example, one EditText is used to input the text. This text is sent to the second activity when the “Send” button is clicked.

How send data from one activity to another in Android?

passing the custom Object in activity,

  1. Pass it to the activity, Intent intent = new Intent(getActivity(), Activity. class); intent. putExtra(“list”, (Serializable) mainData. getData(). getFeaturedProduct()); getActivity(). …
  2. And get it. ((List) getIntent(). getExtras(). getSerializable(“list”))

30 сент. 2017 г.

How do you share data between activities?

Send data inside intents

putExtra(“some_key”, value); intent. putExtra(“some_other_key”, “a value”); startActivity(intent); On the second activity: Bundle bundle = getIntent().

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.