How do you pass data between activities in an Android application?
We can send the data using putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.
To pass data between two activities, you will need to use the Intent class via which you are starting the Activity and just before startActivity for ActivityB, you can populate it with data via the Extra objects. In your case, it will be the content of the editText.
Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.
in your current activity, create an intent
Intent i = new Intent(getApplicationContext(), ActivityB.class); i.putExtra(key, value); startActivity(i);
then in the other activity, retrieve those values.
Bundle extras = getIntent().getExtras(); if(extras !=null) { String value = extras.getString(key); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With