How can I detect if an activity came to focus after pressing the back button from a child activity, and how can I execute some code at that time?
You can also override both the onBackPressed() method and the onOptionsItemSelected() method and put some logic there. For example I put this into my BaseActivity which all the other Activities extends from:
@Override
public void onBackPressed() {
// your logic
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// your logic
}
return super.onOptionsItemSelected(item);
}