If you need a special behaviour of ActivityA
when coming back from ActivityB
, you should use startActivityForResult(Intent intent, int requestCode)
instead of startActivity(Intent intent)
:
startActivityForResult(new Intent(this, ActivityB.class), REQUEST_CODE);
This way, you will be able to detect ActivityB
's termination 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(); // your "refresh" code
}
}
This works even if you terminate ActivityB
by the press of the back button. The resultCode
will be RESULT_CANCELLED
by default in that case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…