0

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..

uul
  • 9
  • 5
  • Check [this](https://stackoverflow.com/questions/64851765/how-to-clear-jetpack-datastore-data-on-specific-condition) answer – Sky May 11 '22 at 12:30

1 Answers1

3

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()
 }