状态跨越多个 Activity 的视图
如何创建其状态跨越多个活动的自定义视图?创建自定义视图并不是困难的部分。
具体来说,我使用的是滑动抽屉,并且我希望该抽屉在出现在多个活动中时保持其状态。我还没有看到这样做的编码示例,希望其他人看到过。谢谢。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于它应该跨越多长时间。您可能需要考虑将其状态存储在 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.