如何在Kotlin的Preferences数据存储中设置注销

发布于 2025-01-28 03:13:33 字数 78 浏览 5 评论 0原文

我们在共享的首选项中使用“ .crear”,以设置按钮注销。但是现在我尝试使用首选项数据存储,但不能使用相同的代码。那怎么?非常感谢您的回答。

We use ".clear" in shared preferences before, to setting the button logout. But now i tried to use preferences datastore, but can't use the same code. So how? Thank you so much for answering..

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

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

发布评论

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

评论(1

不甘平庸 2025-02-04 03:13:33

使用此

dataStore.edit { 
        it.clear()
    }

在任何人想知道如何删除特定偏好的情况下

context.dataStore.edit {
    it.remove(key)
}

方法(对于proto DataStore):

dataStore.updateData { obj ->
    obj.toBuilder()
        .clear()
        .build()
 }

Use this

dataStore.edit { 
        it.clear()
    }

In case anyone wants to know how to remove a specific preference

context.dataStore.edit {
    it.remove(key)
}

Try this (for Proto DataStore):

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