onConfigurationChanged 第一次没有被调用
我在尝试捕获 onConfigurationChanged
事件时遇到问题。这是这样的场景:
- Activity A 启动(监听
onConfigurationChanged
), - 手机旋转到横向模式(
onConfigurationChanged
被调用)。启动活动 B。 - 活动 B 启动(侦听
onConfigurationChanged
)(横向) - 活动 B 旋转回纵向(引发
onBackPressed
事件)。 Activity B 被销毁,A 被回调。 - 活动 A 恢复
- 手机旋转至横向模式。这次没有调用
onConfigurationChanged
。 - 手机旋转至纵向模式。调用的
onConfigurationChanged
。 - 手机旋转至横向模式。调用的
onConfigurationChanged
。
为什么第6步不调用onConfigurationChanged
事件?这根本没有意义。你知道可能是什么问题吗?
I've a problem trying to capture the onConfigurationChanged
event. This is the scenario:
- Activity A starts (listens to
onConfigurationChanged
) - Phone rotated to landscape mode (
onConfigurationChanged
being called). Start activity B. - Activity B starts (listens to
onConfigurationChanged
) (LANDSCAPE) - Activity B rotates back to portrait (
onBackPressed
event raised). Activity B is destroyed and A is called back. - Activity A resumes
- Phone rotated to landscape mode. The
onConfigurationChanged
is not called this time. - Phone rotated to portrait mode. The
onConfigurationChanged
called. - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有同样的问题,我更新 UI
onResume()
来修复它。I have the same problem, I update UI
onResume()
to fix it.我有完全相同的问题。我仍然不明白android系统的这种行为,但是你可以使用
OrientationEventListener
的onOrientationChanged
来代替配置更改处理。请参阅此答案(示例并不完美,但说明了方法):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
ofOrientationEventListener
instead of configuration change handling.See this answer (example is not perfect but shows the way): https://stackoverflow.com/a/13844242/554281
我也遇到过同样的问题,并且被困在这个问题上一个多星期了。然后我用 tabHost 准备了一个示例应用程序,并在示例应用程序上重现了相同的问题。经过一番研究,我发现这是android tabHost 的一个bug。因此,我将 tabHost 迁移到 FragmentTabHost 并发现问题消失了。
tabHost 问题的模拟:
假设有两个选项卡,即 A 和 B
模拟 1(出现 bug)
模拟 2(工作正常)
摘要:如果您以与退出时相同的方向返回屏幕,则 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)
Simulation 2 (Works fine)
Summary: If you get back to the screen in the same orientation you got out, both onConfigurationChanged() will get called.