简体   繁体   中英

If my GLSurfaceView app never needs to read the Android device's locale, can I safely ignore locale config changes?

By default, if the user changes the display language of their device while my app is running, Android will destroy then recreate the Activity. It does this to be sure my app is correctly using the latest settings.

I can override this behaviour by adding locale to the configChanges attribute in the manifest. Then when the user changes language, I will only get a callback to onConfigChanged() rather than a full restart. However the documentation says I should "retrieve all resources" again:

All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.

My question is, is this really true for locale changes? If I have a hypothetical app that never makes use of the user's language settings at all, and renders only graphics, using a GLSurfaceView, is it safe to just ignore this event? If so, can you back that up with documentation?

Ignoring the event seems to function correctly, and it doesn't make much sense to recreate the view when I'm not making any use of the locale anyway, but I want to be sure I'm not introducing some subtle bugs.

Any infomation much appreciated.

As you said, your GLSurfaceView is completely locale independent, it's ok to add locale to configChanges as it's ok to add keyboard or screenSize if you're layout never changes depending on those configurations.

Edit: Documentation: http://developer.android.com/guide/topics/resources/runtime-changes.html

However, you might encounter a situation in which restarting your application and restoring significant amounts of data can be costly and create a poor user experience. In such a situation, you have two other options:

[...]

b. Handle the configuration change yourself

Prevent the system from restarting your activity during certain configuration changes, but receive a callback when the configurations do change, so that you can manually update your activity as necessary.

Also: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM