I know, that I get the same result with both code snippets
finish(); startActivity(newActivity);
and
startActivity(newActivity); finish();
I'd like to know your opinion, if there is a big difference between them. Is one better than the other? If so, why?
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
When you do startActivity(), all that does is post your intent in a queue of events. The actual starting of the activity happens asynchronously in the near future. So I don't see a big difference between the two.
The animation is clearly different (at least on 4.1 onwards). Calling finish()
first starts to fade away the first activity earlier and you can briefly see a black background before the new activity fades in. Calling startActivity()
first fades in the new activity on top of the old one and the black background is not visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With