As we know, android destroys and restarts an Activity when the user switches between portrait and landscape modes which we can prevent by overriding the onConfigurationChanged() callback. Can any one please explain to me what the actual need for the system to destroy and start the activity? Are there any side effects if I override onConfigurationChanged()?
As we know, android destroys and restarts an Activity when the user switches between
Share
The main purpose of restarting the Activity is because Android needs to change layouts, resources, etc. to adapt to the new screen orientation. As you may know, each orientation (usually) has its own Application Resources. The designers of Android decided it would be best to simply restart the Activity because so much reworking needs to be done in changing resources.
This is especially important after Honeycomb came out with the appearance of Fragments. Depending on your orientation, you can be displaying a completely different set of Fragments and associated sets of data.
I would strongly recommend against overriding
onConfigurationChanged(). Instead, read the link HandlerExploit provided in his answer. It shows how to handle orientation changes more efficiently usingonRetainNonConfigurationInstance().