This question already has an answer here:
I have an app which shows fullscreen bitmaps in an activity. In order to provide fast loading time, I load them in the memory. But when the screen changes orientation, I would like to clear the cache in order to fill it again with bitmaps that fit inside the new dimensions. The only problem is that in order to do this, I need to detect when an orientation change occurs. Do anyone know how to detect this?
Another approach is using OrientationEventListener.
It can be used like this:
To check orientation:
And don't forget to enable and disable listener:
You can check the
onSavedInstanceState
from youronCreate
method, if it is not null means this is configuration change.See the official documentation http://developer.android.com/guide/topics/resources/runtime-changes.html
Changing it will actually create a new view and onCreate will be called again.
Furthermore you can check it via
Usually Orientation change calls
OnCreate()
unless you have done something to make it do otherwise.You can put the logic there.