It doesn't matter in what order I call finish () and startActivity ()?

First way

Intent in = new Intent(VerificationActivity.this, VerifyCode.class);
in.putExtra("verificationCode", verificationCode);
finish();
startActivity(in);

The second way ...

Intent in = new Intent(VerificationActivity.this, VerifyCode.class);
in.putExtra("verificationCode", verificationCode);
startActivity(in);
finish();

what's better? is there any difference

+4
source share
2 answers

finish()call the onStop()current activity, and startActivity(i)moves the new one intent ito the event queue. and the activity starts when it is removed from the event queue. in the first case, if the queue of events is stopped, you will see that the current activity disappears, and after some time, when the intention begins to turn, the activity will appear out of nowhere. but thanks to Android planning, this almost never happens.

+1
source

, , startActivity() finish() . , return.

0

Source: https://habr.com/ru/post/1612387/


All Articles