Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finish old activity and start a new one or vice versa

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?

like image 645
Tima Avatar asked Nov 15 '10 08:11

Tima


People also ask

How do you finish an activity?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.


2 Answers

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.

like image 65
Emmanuel Avatar answered Sep 20 '22 07:09

Emmanuel


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.

like image 27
Monstieur Avatar answered Sep 21 '22 07:09

Monstieur