In my MainActivity onCreate I have a button listener which switches to a second activity:
editorLink.setOnClickListener {
val intent = Intent(this, EditorActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent)
}
In my second activity I have another button listener which attempts to switch back to the first activity, passing it some new data:
saveButton.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("my_data", "my data from other activity");
startActivity(intent)
}
Then in my MainActivity onStart I attempt to read the extra data:
if (intent.extras != null) {
myData = intent.extras!!.getString("my_data")
}
However the intent.extras is always null here.
I have put Logger calls everywhere and I am sure all the above code is being run and the data being added to extras is a valid string.