Android:TabHost Activity 在终止/未调用 OnSaveInstanceState 后表现得很奇怪
我不确定我是否做错了什么,但当我偶然发现 类似的错误,它也可能是另一个错误。我想知道你是否可以证实这一点,甚至知道解决方案?
好的,我有一个包含两个活动 A 和 B 的选项卡主机。A
是“第一个”选项卡。因此,如果我执行以下操作:
- (A 打开)
- 切换 B
- 关闭应用程序
- 杀死进程
- 再次
- 打开应用程序(B 显示)
那么我一切都很好。使用日志我看到A和B都调用了“onRestoreInstanceState”。
现在,我执行以下操作:
- (B已打开,我没有切换回A)
- 切换B
- 关闭应用程序
- 杀死进程
- 再次
- 打开应用程序(B显示)
然后 B 会调用“onRestoreInstanceState”,但 A 不会。A 在“onCreate”中得到一个 null Bundle。
如果我切换到A,然后再切换回B,就又没问题了。之后,我可以重复上述行为。
我知道这听起来有点令人困惑,但是以前有人遇到过这种情况吗?
亲切的问候, jellyfish
编辑:
我已经对另一个选项卡重复了此操作(保持 A 打开,终止活动,恢复它,再次终止它,再次恢复它)。然后,直到我故意切换选项卡时,B的“onCreate”才被调用;并且无论之前是否恢复过,它总是会获取SavedInstance Bundle。所以一切都很好。
编辑2:
除此之外,旋转更改也是如此。以前真的没有人注意到这一点吗?在 2.2 模拟器和 2.3 手机上都可以使用。
I am not sure if I am doing something wrong, but as I just stumbled upon a similar bug, it might be another bug as well. I was wondering if you could confirm this or even know a solution?
Okay, so I have a Tab Host containing two Activities A and B.
A is the "first" tab. So if I do the following:
- (A is opened)
- switch B
- close app
- kill the process
- open app again
- (B shows up)
then I everything is fine. Using Log I see that "onRestoreInstanceState" was called both for A and B.
Now, I do the following:
- (B is opened, I have NOT switched back to A)
- switch B
- close app
- kill the process
- open app again
- (B shows up)
then "onRestoreInstanceState" is called for B, but not for A. A get's a null Bundle in "onCreate".
If I switch to A, then back to B, it's fine again. After that, I can repeat the above behavior.
I know this sounds a bit confusing, but has anybody encountered this before?
Kind regards,
jellyfish
Edit:
I've repeated this for the other tab (keep A open, kill the activity, restore it, kill it again, restore it again). Then, B's "onCreate" is not called until I deliberately switch the tab; and no matter if it was restored before or not, it always gets the SavedInstance Bundle. So everything is fine.
Edit2:
As excepted, the same is true for rotation changes. Has seriously nobody noticed this before? Got this working both on 2.2 emulator and 2.3 phone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论