当 setIntent 后面跟着旋转时 getIntent 返回错误的意图
我有以下场景:
我有一个聊天活动,它的意图是获取要显示消息的联系人的电子邮件,该活动具有 singleTop 因为它的启动模式
通过在屏幕上滑动我的手指,我在不同的对话之间切换,我通过使用新意图调用 startActivity 来执行此操作:将调用 onPause,然后调用 onNewIntent,其中我执行 setIntent,然后调用 onResume。在 onResume 中我得到了新的意图,到目前为止一切都很好。
然后我改变方向:调用 onPause,然后调用 onDestroy,此时 getIntent 返回正确的意图,然后是具有旧意图的 onCreate,然后是 onResume,它也具有旧意图
我发现了这个 -> http://groups.google.com/group/android-developers/browse_thread /thread/7f0389f349e1ee3b 来解释这种行为,但它不会发生在我对 Android 2.2 的 HTC 愿望上,使用模拟器我发现它发生在 1.5 上,但不会发生在 1.6 上
所以我的问题:这在 1.5 上正常吗?如果是这样,我怎样才能改变活动的行为,以免再次发生这种情况?
我知道我可以将启动模式从 singleTop 更改为标准,但这也会影响 android 1.6+,这是我不想要的,因为使用 singleTop,对话的更改速度很快(仅调用 onPause 和 onResume),而标准 onCreate 和 onDestroy 是也称为...
也许我可以用我还没有找到的意图标志做一些事情,我在代码中更改标志,这样我就可以进行“if sdk is 3”检查...
感谢您的阅读,Danny
I have the following scenario:
I have a chat activity, in it's intent it gets the email of the contact for which to show the messages, the activity has singleTop as it's launchmode
By sliding my finger over the screen I switch between different conversations, I do this by calling startActivity with the new intent: onPause will be called, followed by onNewIntent, in which I do setIntent, followed by onResume. In onResume I get the new intent, all good so far.
Then I change the orientation: onPause is called, followed by onDestroy, at this point getIntent returns the correct intent, followed by onCreate which has the old intent, followed by onResume, which also has the old intent
I've found this -> http://groups.google.com/group/android-developers/browse_thread/thread/7f0389f349e1ee3b to explain this behavior but it doesn't happen on my HTC desire with android 2.2, using the emulator I found it happens on 1.5, but not on 1.6
So my question: Is this normal on 1.5 ? If so, how can I change the behavior of the activity so this doesn't happen again ?
I know I can change the launchmode from singleTop to standard but this will also affect android 1.6+ which I don't want because with singleTop, the changing of conversation goes fast (only onPause and onResume are called), with standard onCreate and onDestroy are also called...
Maybe there is something I can do with the intent flags I haven't found yet, the flags I change in the code so I can have a "if sdk is 3" check...
Thanks for reading, Danny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过覆盖
onRetainNonConfigurationInstance()
并返回最新的意图来解决这个问题,然后您可以使用getLastNonConfigurationInstance()
检索该意图。You can possibly work around it by overriding
onRetainNonConfigurationInstance()
and return the latest intent, which you can then retrieve usinggetLastNonConfigurationInstance()
.