If you need special ActivityA behavior when returning from ActivityB , you should use startActivityForResult(Intent intent, int requestCode) instead of startActivity(Intent intent) :
startActivityForResult(new Intent(this, ActivityB.class), REQUEST_CODE);
That way, you can detect the completion of ActivityB in ActivityA by overloading onActivityResult(int requestCode, int resultCode, Intent intent) :
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == REQUEST_CODE) { doRefresh();
This works even if you end ActivityB by clicking the back button. In this case, resultCode will be RESULT_CANCELLED .
Shlublu
source share