Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why onCreate is called on Activity when rotating android tablet?

onCreate method is called every time on Activity whenever screen is rotated. Is it just onCreate being called again or whole activity is re-created?

like image 823
jM2.me Avatar asked Dec 21 '22 14:12

jM2.me


1 Answers

It is not just onCreate(). When the screen is rotated, the activity is paused, stopped, and restarted. See this question for more info: Activity lifecycle - onCreate called on every re-orientation

If the question is "Why does this happen?" the answer has to do with functionality inside of Android's activities and windows. More specifically, android currently does not have a way to move, resize, and relayout each and every view when the orientation is changed. To make handling this scenario possible, the simpler implementation of just tearing down the activity and bringing it back up in a different orientation was implemented.

like image 149
spatulamania Avatar answered Apr 09 '23 15:04

spatulamania