Activity A
call Activity B
Activity C
Activity B
Don't call finish()
from B when opening C. Instead, call C with startActivityforResult()
and then pass the data back through B when onActivityResult()
in B is triggered. Something like:
ActivityB {
onCreate(Bundle) {
startActivityForResult(ActivityC, 0);
}
onActivityResult(int, int, Intent){
setResult(resultCode, data);
finish();
}
}
Edit:
Apparently adding the flag Intent.FLAG_ACTIVITY_FORWARD_RESULT
when calling B should actually achieve your desired result as well.
Learn somethin' new every day...
use shared preference
C ACTIVITY
SharedPreferences sf = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sf.edit();
editor.putString(key, value);
editor.commit();
A ACTIVITY
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
String savedPref = sharedPreferences.getString(key, "");
mOutputView.setText(savedPref);
Where're multiple ways of doing this:
Store the data from Activity C
to Application's object and just read it in Activity A
:
((MySuperApplication) getApplication()).setMyData(..);
Pass it as Activity Result
SharedPreference
in Activity C
and read it in Activity A
. If it's a complex data structure - I'd suggest to use gson
to serialize object and store it as a string
and then deserialize it in Activity A
Choose the one you like the most.