onConfigurationChanged 第一次没有被调用

发布于 2024-11-02 01:23:06 字数 622 浏览 2 评论 0原文

我在尝试捕获 onConfigurationChanged 事件时遇到问题。这是这样的场景:

  1. Activity A 启动(监听 onConfigurationChanged),
  2. 手机旋转到横向模式(onConfigurationChanged 被调用)。启动活动 B。
  3. 活动 B 启动(侦听 onConfigurationChanged)(横向)
  4. 活动 B 旋转回纵向(引发 onBackPressed 事件)。 Activity B 被销毁,A 被回调。
  5. 活动 A 恢复
  6. 手机旋转至横向模式。这次没有调用onConfigurationChanged
  7. 手机旋转至纵向模式。调用的onConfigurationChanged
  8. 手机旋转至横向模式。调用的onConfigurationChanged

为什么第6步不调用onConfigurationChanged事件?这根本没有意义。你知道可能是什么问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不忘初心 2024-11-09 01:23:06

我有同样的问题,我更新 UI onResume() 来修复它。

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

dawn曙光 2024-11-09 01:23:06

我有完全相同的问题。我仍然不明白android系统的这种行为,但是你可以使用OrientationEventListeneronOrientationChanged来代替配置更改处理。

请参阅此答案(示例并不完美,但说明了方法):https://stackoverflow.com/a/13844242/554281

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

世界如花海般美丽 2024-11-09 01:23:06

我也遇到过同样的问题,并且被困在这个问题上一个多星期了。然后我用 tabHost 准备了一个示例应用程序,并在示例应用程序上重现了相同的问题。经过一番研究,我发现这是android tabHost 的一个bug。因此,我将 tabHost 迁移到 FragmentTabHost 并发现问题消失了。

tabHost 问题的模拟:

假设有两个选项卡,即 A 和 B

模拟 1(出现 bug)

  1. 纵向模式到达 A 纵向模式
  2. 到达 B 横向
  3. 模式旋转 B 到横向
  4. 返回 A。
  5. 将 A 旋转为纵向(tabActivity 的 onConfigChanged 方法被触发。但 A 活动的 onConfigChanged 不会被触发)

模拟 2(工作正常)

  1. 以纵向模式到达 A 以
  2. 纵向模式转到 B(继续按需要旋转,但停止纵向模式)
  3. 返回纵向模式 A。
  4. 将 A 旋转到横向(tabActivity 的 onConfigurationChanged 方法和 A 活动都被触发)

摘要:如果您以与退出时相同的方向返回屏幕,则 onConfigurationChanged() 都会被调用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文