6

Is it an atomic operation?

I mean is it possible that anything else gets executed on the main thread during an orientation change?

For example, let's say the flow on the main thread is something like this:

someOperation -> orientationChangeStart -> someOtherOperation -> orientationChangeEnd

Is this possible?

Can someOtherOperation get executed on the UI thread while an orientation change is in progress?

Thanks in advance.

justanoob
  • 1,797
  • 11
  • 27

2 Answers2

3

Yes, it is atomic operation.

in pseudo it looks like:

void setNewOrientation(int state) {
    currentState = state;
    runOrientationChangedEvent();
}

And then usually Activity is re-created. Only re-creating of Activity adds to the message queue, so it is possible to see if change device orientation fast enough.

You cannot get start and end of this process, because it just changes a few int variables which can tell you about current orientation like orientation:

getActivity().getResources().getConfiguration().orientation

or rotation

getWindowManager().getDefaultDisplay().getRotation();

So you can get event only after orientation is changed.

Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
2

Probably you will not be able to measure time between orientationChangeStart and orientationChangeEnd but you can execute your someOtherOperation handling onConfigurationChanged event. Example: How to use onConfigurationChanged() and newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE in android 2.3.3

Community
  • 1
  • 1
user61253764
  • 478
  • 5
  • 9