OnConfigurationChanged does not receive a call for the first time

I have a problem capturing the onConfigurationChanged event. This is the scenario:

  • Action A starts (listens onConfigurationChanged )
  • The phone is rotated to landscape mode ( onConfigurationChanged ). Start operation B.
  • Action B starts (listens onConfigurationChanged ) (LANDSCAPE)
  • Action B rotates back to the portrait ( onBackPressed event raised). Activity B is destroyed, and A is called back.
  • Activity A resumes
  • The phone is rotated to landscape mode. This time onConfigurationChanged not called.
  • The phone is turned into portrait mode. Called onConfigurationChanged .
  • The phone is rotated to landscape mode. Called onConfigurationChanged .

Why does step 6 not trigger the onConfigurationChanged event? it makes no sense. Do you know what could be the problem?

+4
source share
3 answers

I have the same problem, I am updating the onResume() UI to fix it.

+1
source

I had exactly the same problem. I still do not understand this behavior of the Android system, but instead of> you can use onOrientationChanged OrientationEventListener .

See this answer (the example is not perfect, but shows the way): fooobar.com/questions/928642 / ...

0
source

I ran into the same problem and got stuck in it for more than a week. Then I prepared a sample APP with tabHost and reproduced the same problem in the sample application. After playing around with this, I found that this is an android tabHost error. So, I moved tabHost to FragmentTabHost and found that the problem is gone.

Modeling problems with tabHost:

Suppose there are two tabs ie A A and B

Simulation 1 (Recover Error)

  • Arrival in portrait mode
  • Switch to B mode in portrait mode.
  • Turn B to album
  • Returns to A mode in landscape orientation.
  • Turn A into portrait (onConfigChanged method tabActivity will be launched, but onConfigChanged from A will not be activated)

Simulation 2 (works great)

  • Arrival in mode A in portrait mode
  • Go to B mode in portrait mode (keep spinning as you want, but stop in portrait mode)
  • Returns to portrait mode.
  • Turn A to landscape (both the onConfigurationChanged tabActivity method and A are activated)

Summary: If you return to the screen with the same orientation as you selected, the onConfigurationChanged () call is called.

0
source

All Articles