安卓。保存对话框的实例状态?
我想知道实施这个的正确方法是什么?有人可以建议我的解决方案是否正确吗?
因此:
- 创建活动
- 用户单击按钮并启动对话框(对话框,不是对话框样式的活动)
- 用户打开键盘
- ,我们调用了 onSaveInstanceState 来保存对话框已打开的位置以及
- 我们拥有 onRestoreInstanceState 的所有相应对话框输入,在这里我们检查对话框是否显示后,使用相应的输入重新创建对话框。
这是正确的方法吗?或者有某事。这是由 Android 完成的,我正在做一些多余的操作。
谢谢
I wonder what is the right way to implement this? Could anybody advice whether my solution is correct?
So:
- Activity is created
- User clicks on button and dialog is launched (Dialog, not dialog styled activity)
- User opens keyboard
- we have onSaveInstanceState called where we save that our dialog was opened and all respective dialog input
- we have onRestoreInstanceState and here we check whether dialog was shown, recreate the dialog with respective input.
Is it the right approach? or there is smth. that is done by Android and I am doing some redundant actions.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是正确的做法。 对话框不扩展Activity,但它们的工作方式非常相似,您刚刚描述了正确的保存“流程” /恢复任一状态。
Yes, that is the right way to do it. Dialogs don't extend Activitys, but they work very similarly and you've just described exactly the correct "flow" for saving/restoring states for either.
尝试注释掉 onRestoreInstanceState() 并查看应用程序是否仍然加载您希望保存的信息。
我希望这有帮助!干杯。
Try commenting out your onRestoreInstanceState() and see if the application still loads the information that you expected to be saved.
I hope that helps! Cheers.