片段中的伴侣对象与共享偏好
有时,要使用来自其他片段的数据,我使用伴随对象如下所示,
class ExampleFragment : Fragment() {
[...]
companion object {
val myValueToShare = 20f
}
}
在其他片段中,我使用此变量为:
IE
ExampleFragment.myValueToShare = 10f
还可以吗? IE使用共享首选项
更好。 上面的哪些方法更轻,为什么?
https://blog.mindorks.com/companion-object-in-kotlin#:~: text = So; %20-持续。
Sometimes to use data from other fragment I use companion object as below
class ExampleFragment : Fragment() {
[...]
companion object {
val myValueToShare = 20f
}
}
in other fragment I use this variable as:
i.e.
ExampleFragment.myValueToShare = 10f
Is it alright? Is it better to i.e. use shared preferences
.
Which methods from above are more light and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论