In my activity, I redefine the onConfigurationChanged () method when it plays the video, and I do not want to wait a second until the system is ready to continue playing the video again after changing the orientation of the device. This works very well - my video continues to play smoothly, and the orientation changes, and the video is scaled to just fit the screen size.
However, I found an error while completing these steps:
- I pause my application while playing a video.
- I change orientation
- I am renewing my application
The first thing that happens: onConfigurationChanged () is called, not onResume (), after which all my fields must be restored! This throws an exception with division by zero as the reason - some field is 0, because it has not yet been restored. Of course, this is an undesirable behavior. My application really works when it resumes with the same orientation in which it stopped.
I can get around this, however, using a boolean value indicating whether my activity was "fully loaded", that is, the onResume () method was called. But I think this is not a very clean solution.
My question is:
- Is this intentional behavior? I find it strange that onConfigurationChanged () is called before onResume (). This is mistake?
Can I programmatically βunregisterβ my application from listening to onConfigurationChanged () temporarily (for example, unregister in the onPause () method)? Since this method is not called because you have to register it as a listener, but it is called because you insert this line into your AndroidManifest.xml file:
Android: configChanges = "orientation"
source share