What are the pros and cons of using configChanges = "orientation" for Android devices?

I want to use android:configChanges="orientation|keyboardHidden" for several of my actions so that my onCreate is not called again, but I thought I'd see if someone had a list of pros and cons because this link says that it should be used only as a last resort.

+7
source share
2 answers

The big Pro using this approach is that it requires very little effort on your part and that your application will be able to survive configuration changes without resorting to crashes.

A small drawback is that the use of configuration resources (for landscape or portrait orientation) is not automatically applied.

In my (perhaps a little) experience, I think it's not worth it to do all the plumbing.

"Correct" processing of these configuration changes requires a lot of plumbing on your part, and everything becomes even more dramatic if you need to maintain progress dialogs during screen orientation changes.

Although most people prefer a quick fix by modifying the manifest and customizing their activity with android: configChanges = "keyboardHidden | orientation", I think it's important to realize that there are alternatives to this.

This requires more code, but it gives you a better idea of ​​how the overall system works.

+5
source

It's strange that Google doesn't really talk anymore about the reasons behind this, but there are three main reasons I can think in order to avoid using this approach:

  • In my experience, some types of views (in particular WebViews and MapViews on Android 2.1 or lower) can behave rather strangely after changing the orientation if they were not recreated (for example, the zoom buttons are incorrectly configured).
  • This prevents the use of orientation layouts (see, for example, the new landscape view of the Market application).
  • This may prevent you from discovering the erroneous behavior of your application due to other reasons why your activity may be destroyed and recreated (for example, with low memory or with other normal killers in the background). That is, if your activity can gracefully handle a restart due to rotation, perhaps it can restart due to a background kill. However, if you skip rotation processing, you may not encounter a reboot due to background killing during routine testing until a user with an older low memory phone writes an error message.

The last reason is great; especially with older low-RAM phones and supposedly more aggressive auto-skinning modes in Gingerbread, your actions should know how to quickly recreate after destruction, maintaining its state regardless of orientation. And as soon as your activity can cope with such types of destruction / rest, you are probably all set to change rotation anyway. You can get some speed by absorbing a rotation event (since you don’t need to return through layout inflation and all that), but that's about it all, at that moment.

If you decide to learn rotation, I strongly recommend that you always use an emulator or device with the Development.apk option "Kill Actions Immediately", and then make sure that switching applications or backing up through the task stack still works correctly.

In my experience, swallowing corners can actually be a good choice for improving the user experience, especially when working with complex layouts that can take a few minutes to recreate, but you really need to thoroughly and thoroughly test to keep your activity working even without ignoring rotation .

+6
source

All Articles