Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of Application.onConfigurationChanged

Tags:

android

EDIT : I know how to handle configuration changes; this query is on using 'Application' class for this task.

I can see many examples where Application class is being used as a "global" to maintain state variables. But I am curious is knowing the use of methods which I always thought were linked to individual activity lifecycle... like onConfigurationChanged() and registerComponentCallbacks().

I could not find any examples on how to use these methods. I request for some use-cases/patterns where overriding these methods would help.

Thanks !

like image 975
WinOrWin Avatar asked Sep 08 '12 20:09

WinOrWin


1 Answers

The official documentation says:

Unlike activities, other components are never restarted when a configuration changes: they must always deal with the results of the change, such as by re-retrieving resources.

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

Like you said, if you are maintaing "global" state variables you may need to know if some configuration has changed that can affect all your app, probably not orientation or keyboardHidden changes, but some more "global" configuration like locale change. You can check the full list here (https://developer.android.com/guide/topics/manifest/activity-element.html#config)

https://developer.android.com/reference/android/app/Application.html#onConfigurationChanged(android.content.res.Configuration)

like image 174
Cassio Landim Avatar answered Oct 12 '22 23:10

Cassio Landim