状态跨越多个 Activity 的视图

发布于 2024-10-06 17:17:32 字数 118 浏览 0 评论 0原文

如何创建其状态跨越多个活动的自定义视图?创建自定义视图并不是困难的部分。

具体来说,我使用的是滑动抽屉,并且我希望该抽屉在出现在多个活动中时保持其状态。我还没有看到这样做的编码示例,希望其他人看到过。谢谢。

How can I create a custom view whose state spans multiple Activities? Creating a custom view is not the hard part.

To be specific, I am using a sliding drawer, and I want this drawer to maintain it's state as it appears on more than 1 activity. I haven't seen a coded example of doing this, hoping someone else has. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

怼怹恏 2024-10-13 17:17:32

取决于它应该跨越多长时间。您可能需要考虑将其状态存储在 SharedPreferences 中 - 这样,即使您重置手机,它也会持续存在。

如果它“只是很快”,您可以在意图附加中传递状态数据。

您还可以考虑静态变量,但请记住,一旦用户移动到其他内容,您的活动可能会被终止,因此如果用户回来,您可能会丢失状态。

Depends on just how long it should span it. You may want to consider storing its state in the SharedPreferences - that way, it will persist even if you reset the phone.

If it's "just quick", you could pass the state data in the intent extras.

You could also consider static variables, but keep in mind that your activity could be killed off as soon as the user moves to something else, so if the user comes back, you may have lost your state.

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