In my Activity, I override the onConfigurationChanged() method as it's playing a video, and I do not want to wait a second until the system is ready again to continue playing the video after I change my device's orientation. This works just fine - my video keeps playing smoothly and the orientation gets changed, while the video gets rescaled to just fit in the screen dimensions.
Yet I discovered a bug when these steps are taken:
First thing what happens: onConfigurationChanged() gets called, not onResume() after which all my fields should be restored! This causes an Exception with a divide by zero as its cause - some field equals 0 as it's not restored yet. Ofcourse this is not desired behaviour. My app does work when resuming it with the same orientation it's paused in.
I can circumvent this, though, by using a boolean indicating whether my Activity has "fully loaded" - that is, the onResume() method has been called. But I consider this not a very clean solution.
My question is:
Can I programmatically "unregister" my app from listening to onConfigurationChanged() temporarily (for example, unregister it in the onPause() method)? As this method does not get called because you must register some listener to it, but gets called because you put in your AndroidManifest.xml file this line:
android:configChanges="orientation"
1- answer in http://developer.android.com/reference/android/app/Activity.html
In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.
so its normal that onconfugrationchanged is called earlier to allow changing before starting activity again.. 2- I am not sure about this ..
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