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 !
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With