2

I was creating an app that supports pip mode. I came across android:configChanges. What does it do?

Aditya
  • 325
  • 6
  • 19
  • Does this answer your question? [What does the android:configChanges="screenSize" attribute do?](https://stackoverflow.com/questions/25120903/what-does-the-androidconfigchanges-screensize-attribute-do) – a_local_nobody Dec 07 '20 at 13:41
  • perhaps also relevant : https://stackoverflow.com/questions/7818717/why-not-use-always-androidconfigchanges-keyboardhiddenorientation – a_local_nobody Dec 07 '20 at 13:42
  • `android:configChanges="smallestScreenSize|orientation|screenSize|screenLayout"`, what does this do? – Aditya Dec 07 '20 at 14:01

1 Answers1

11

In Android, when device configuration changes (such as users rotate the screen orientation, change language, etc..), the system will restart the running Activity (onDestroyed() is called, followed by onCreate()) to apply the new configuration.

If your application doesn't want this behavior to happen (maybe you don't want to restart the running activity or you want to apply the new configuration by yourself), then you can declare that the activity will handle the configuration by itself which preventing the system from restarting the activity.

To do that you go to the AndroidManifest.xml file, find the appropriate <activity> tag, add the android:configChanges attribute with a value that represents the configuration you want to handle.

Now when the configuration changes, the system does not restart your activity. Instead your activity will receive a call to onConfigurationChanged(Configuration) method along with the new configuration.

You should go to activity-element, read the "android:configChanges" section, you will understand it clearly. By the way, Android provides documentation about how to handle configuration changes in runtime here.

Son Truong
  • 13,661
  • 5
  • 32
  • 58