Android: finish() refreshes the activity
I have activity A and B. Activity A calls B with the following codes:
Intent iSettings = new Intent(A.this, B.class);
startActivityForResult(iSettings, ACTIVITY_SAVE_PREF);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
startActivity(iSettings);
Activity B finishes and go back to Activity A by pressing the BACK button which has the following code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Bundle bundle = new Bu开发者_如何转开发ndle();
bundle.putBooleanArray(KEY_PREFERENCES, value);
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
return true;
}
return super.onKeyDown(keyCode, event);
}
My problem is that Activity B refreshes to its first state it was called by Activity A on the first onKeyDown Back
. Activity B only finishes on the second onKeyDown Back
and successfully returning to Activity A.
Could anyone help me and tell me if I'm missing something please? Thanks so much in advance!
Intent iSettings = new Intent(A.this, B.class);
startActivityForResult(iSettings, ACTIVITY_SAVE_PREF); //here
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
startActivity(iSettings); // and here
Your starting your activity twice, so what you think is a refresh, is just you closing the second activity and the first one is behind it
you avoid using two StartActivity... only one is enough...because if called twice..one Activity behind another Actiivty...
精彩评论