安卓。保存对话框的实例状态?

发布于 2024-08-05 15:30:18 字数 328 浏览 3 评论 0原文

我想知道实施这个的正确方法是什么?有人可以建议我的解决方案是否正确吗?

因此:

  1. 创建活动
  2. 用户单击按钮并启动对话框(对话框,不是对话框样式的活动)
  3. 用户打开键盘
  4. ,我们调用了 onSaveInstanceState 来保存对话框已打开的位置以及
  5. 我们拥有 onRestoreInstanceState 的所有相应对话框输入,在这里我们检查对话框是否显示后,使用相应的输入重新创建对话框。

这是正确的方法吗?或者有某事。这是由 Android 完成的,我正在做一些多余的操作。

谢谢

I wonder what is the right way to implement this? Could anybody advice whether my solution is correct?

So:

  1. Activity is created
  2. User clicks on button and dialog is launched (Dialog, not dialog styled activity)
  3. User opens keyboard
  4. we have onSaveInstanceState called where we save that our dialog was opened and all respective dialog input
  5. 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 技术交流群。

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

发布评论

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

评论(2

债姬 2024-08-12 15:30:18

是的,这是正确的做法。 对话框不扩展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.

过去的过去 2024-08-12 15:30:18

尝试注释掉 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.

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