There is ComponentCallbacks interface in android using by activity, ActivityGroup, service etc. They implements it and someone notify them when activity configuration changed. So, I want to create my own class which implements ComponentCallbacks listens for onConfigurationChanged and doing some actions… So my class is implementing, but… I guess I need to register my class in someone’s observer.
So, is it possible? Is there any ways to “register” my own class to be notified when configuration changed?
I guess this someone may be ActivityThread and it’s method collectComponentCallbacksLocked. But I did’t see here any ways to register my own class.
ActivityThread and
ComponentCallbacks using
p.s. Of course I can override activity’s method onConfigurationChange change and then call the onConfigurationChanged method of my class, but I don’t want. I want to know if there is any way in android to do it.
In the “Google I/O 2012 – Doing More With Less: Being a Good Android Citizen ” talk (which you can find on youtube), it’s explained that you can do this by calling
Context.registerComponentCallbacks.So, you just make your class implement the
ComponentCallbacksinterface (orComponentCallbacks2as you wish), the methods that you can override are added automatically, and from your Activity, Fragment.. just pass the instance from your class to register to it. Something like this:That should do the work 🙂