Android switching language program flashes back and has no effect

Scenario 1. After internationalization, manually modify the settings on the mobile phone, and the application is in the background at this time

Because in 4.2, after the app is configured with the configChanges locale attribute, when the app is in the background and is not finished, if the language is changed, the onConfigurationChanged function rewritten by the Activity will not be called when the resume is resumed.

4.2 adds a layoutDirection attribute, when the language setting is changed, this attribute will also generate a mask bit in newConfig. So ActivityManagerService (actually in ActivityStack) is always judged to be restarted when deciding whether to restart the Activity.

When both locale and layoutDirection are added in android:configChanges, what the app expects happens.

The solution is to add in each activity of manifest.xml : android:configChanges="locale|layoutDirection"

Scenario 2: Switch languages ​​within the app (without exiting the app)

In the Activity of setting the language, after clicking Save, the system language has taken effect, the problem to be solved now is: how to refresh the interface after returning.

Add onCreate(null) to the Activity---onResume() that needs to be returned, which means reloading the page.

Guess you like

Origin blog.csdn.net/cao2884388/article/details/123706555