Does changing the configuration Kill the App and Restart it?

允我心安 提交于 2020-01-07 01:19:12

问题


I was reading This Tutorial section 6.1. And it says that, changing the configuration of an App causes the App to Restart?

My question is, in what sense the App would Restart? does it mean that when the configuration changes, onStop() then onCreate() will be called? But this only happens when another App with higher priority needs memory!

OR

In the sense that, the onStop() then onRestart() then onStart() will be called?

I created a sample App, with only onCreate() callback and with a Log statement, and every time I re-orient the device, the Log statement displays @onCreate() does it mean that changing the configuration of the App. causes it to be killed and restarted over and calls onCreate() again?

kindly please clarify it if possible


回答1:


The app is not killed an restarted.

Your Activity will, however, be recreated.

If you think about how an Activity's layout can be changed when the device is rotated, this makes sense. If you have a portrait layout in your layout/ folder and and landscape layout in your layout-land/ folder, then Android will need to destroy the Activity and recreate it with the new layout.



来源:https://stackoverflow.com/questions/26385052/does-changing-the-configuration-kill-the-app-and-restart-it

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