From my MainActivity
, I have a button that takes me to a Activity A
now, I have some functions inside Activity A
that generates some string data.
What I wanted was, after that string data is generated, I want to go back to MainActivity
with some value from Activity A
and set that to an EditText.
So I tried this...
In my MainActivity
, I have a method that will be called when the method in Activity A
that generates that string data is triggered. It looks like this...
MainActivity
public void receiveData(String data) {
EditText ed = (EditText) findViewById(R.id.eText);
ed.setText(data);
}
Activity A
MainActivity mainActivity;
public void onCreate() {
...
...
mainActivity = new MainActivity();
}
public void generateSomeResult() {
...
...
mainActivity.receiveData(some_string_result);
//I tried calling MainActivity in two ways
//This one causes MainActivity to not fully load maybe why the EditText is not setting the value.
Intent intent = new Intent(this, MainActivity.this);
startActivity(intent);
//This one causes the MainActivity to fully reload and erased the passed value from Activity A maybe why the value set to EditText has not been set.
finish();
}
Now I'm stuck on what to do. Any idea how to achieve this?
question from:
https://stackoverflow.com/questions/65829421/go-back-from-another-activity-to-mainactivity 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…