lblasa
lblasa

Reputation: 6374

onConfigurationChanged not getting called the first time

I've a problem trying to capture the onConfigurationChanged event. This is the scenario:

  1. Activity A starts (listens to onConfigurationChanged)
  2. Phone rotated to landscape mode (onConfigurationChanged being called). Start activity B.
  3. Activity B starts (listens to onConfigurationChanged) (LANDSCAPE)
  4. Activity B rotates back to portrait (onBackPressed event raised). Activity B is destroyed and A is called back.
  5. Activity A resumes
  6. Phone rotated to landscape mode. The onConfigurationChanged is not called this time.
  7. Phone rotated to portrait mode. The onConfigurationChanged called.
  8. Phone rotated to landscape mode. The onConfigurationChanged called.

Why step 6 don't call onConfigurationChanged event? it doesn't make sense at all. Do you know what could be the issue?

Upvotes: 4

Views: 1636

Answers (3)

Ujjal Suttra Dhar
Ujjal Suttra Dhar

Reputation: 846

I have faced same problem and was stuck in this for more than a week. Then I have prepared a sample APP with tabHost and reproduced the same issue on the sample app. After playing around with that, I found that this is a bug of android's tabHost. So, I have migrated tabHost to FragmentTabHost and found the problem is gone.

The simulation of the Issue with tabHost:

Let, there are two tab i.e A and B

Simulation 1 (Arise the bug)

  1. Arrive on A in portrait mode
  2. Go to B on portrait mode
  3. Rotate B to landscape
  4. Back to A on landscape mode.
  5. Rotate A to portrait (onConfigChanged method of tabActivity gets fired. But onConfigChanged of A activity doesn't get fired)

Simulation 2 (Works fine)

  1. Arrive on A in portrait Mode
  2. Go to B on portrait mode (continue rotating as you want, but stop on portrait mode)
  3. Back to A on portrait mode.
  4. Rotate A to landscape (both onConfigurationChanged method of tabActivity and A activity gets fired)

Summary: If you get back to the screen in the same orientation you got out, both onConfigurationChanged() will get called.

Upvotes: 0

Andrei Buneyeu
Andrei Buneyeu

Reputation: 6680

I had exactly the same issue. I still don't understand this behavior of android system, but you can use onOrientationChanged of OrientationEventListener instead of configuration change handling.

See this answer (example is not perfect but shows the way): https://stackoverflow.com/a/13844242/554281

Upvotes: 0

Kevin Ha
Kevin Ha

Reputation: 11

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

Upvotes: 1

Related Questions