I’ve 2 activities, Activity1 and Activity2.
In Activity1 I’ve a Button and TextView.
When the button is clicked Activity2 is started.
In Activity2 I’ve an EditText.
I want to display the data retrieved from EditText in Activity2 in the TextView in Activity1 when back is pressed from Activity2.
can someone help me with the code to make this work?
Start Activity2 with
startActivityForResultand usesetResultmethod for sending data back from Activity2 to Activity1. In Activity1 you will need to overrideonActivityResultfor updatingTextViewwithEditTextdata from Activity2.For example:
In Activity1, start Activity2 as:
In Activity2, use
setResultfor sending data back:And in Activity1, receive data with
onActivityResult:If you can, also use SharedPreferences for sharing data between Activities.