Why the android activity get's destroyed on rotation?

青春壹個敷衍的年華 提交于 2019-12-08 01:10:26

问题


I always wondered what is the benefit of destroying activity on rotation? I mean you can specify android:configChanges="orientation|screenSize"and it won't get destroyed but what's the reason for destroying it


回答1:


Because generally the UI gets all messed up when we have built the screen for portrait mode(say) and the screen gets rotated, so android os thinks that we might need to refactor our layout or maybe use a new layout during onOrientationChanged, maybe that's why the activity gets created again




回答2:


Your activity will be destroyed and recreated each time the user rotates the screen. When the screen changes orientation, the system destroys and recreates the foreground activity because the screen configuration has changed and your activity might need to load alternative resources (such as the layout)

also mathematically aspect ratios change - all these constitute to the os recreating the activity to know how to do work -(this might not be 100% true- but true)..



来源:https://stackoverflow.com/questions/27233787/why-the-android-activity-gets-destroyed-on-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!