Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

301
Visualizações
How to clear jetpack datastore data on specific condition

i've been using jetpack datastore for a while, but then i got a problem. I want to clear data in datastore when the app is destroyed. Im using jetpack datastore to persist data only in form

i've searched that sharedPreferences has a clear() function, is there a similar function for Jetpack Datastore ? and how can i use it ?

i found clear function in datastore documentation but there is no explanation on how to use it

over 4 years ago · Hanz Gallego
5 Respostas
Responde à pergunta

0

If you want to delete a specific key then try this

dataStore.edit {
        if (it.contains(key)) {
            it.remove(key)
        }
    } 
over 4 years ago · Hanz Gallego Relatório

0

Use this

dataStore.edit { 
        it.clear()
    }

Method description states

Removes all preferences from this MutablePreferences.

over 4 years ago · Hanz Gallego Relatório

0

For Proto DataStore you can do:

dataStore.updateData { it.getDefaultInstance() }

It doesn't delete the file, but it's effectively the same.

over 4 years ago · Hanz Gallego Relatório

0

Try this (for Proto DataStore):

 dataStore.updateData { obj ->
    obj.toBuilder()
        .clear()
        .build()
 }
over 4 years ago · Hanz Gallego Relatório

0

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

context.dataStore.edit {
    it.remove(key)
}
over 4 years ago · Hanz Gallego Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda