问题
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