Configuration changed (orientation change) and destroying Activities - is this the way it's supposed to work?

前端 未结 4 681
轻奢々
轻奢々 2020-12-31 04:00

I read up on how Android handles \"configuration changes\" - by destroying the active Activity.

I really want to know from Android Team why this is. I would apprecia

4条回答
  •  粉色の甜心
    2020-12-31 04:50

    You should read the Application Fundamentals (specifically, Activity lifecycle). Since Activitys must be able to handle being killed at any time due to memory contraints, etc. it's just a cleaner way to handle rotations without adding too much complexity - instead of checking every resource for an alternate resource, re-structuring the layout, etc. you just save your essential data, kill the activity, re-create it, and load the data back in (if you're willing to deal with the extra complexity of managing this yourself, you can use onConfigurationChanged to handle the configuration change yourself.) This also encourages better practices - developers have to be prepared for their Activity to be killed for orientation change, which has the (good) consequence of being prepared for being killed off by memory contraints also.

提交回复
热议问题