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

132
Visualizações
Cordova Android LocalStorage loses last saved item when removing battery/running out of battery

Versions: Cordova: 10.0.0 Cordova-Android: 9.0.0

Goal: Items saved to the LocalStorage should be persisted immediately and across whatever happens.

Investigation: I first came across this issue when I left the app running over the weekend. When I came back the phone's battery was empty and after starting the app some data of the LocalStorage was lost.

So I did some tests and first I couldn't really reproduce the issue. What I tried: Writing data into LocalStorage (localStorage.setItem('foo', 'bar'))

  • Force quit the app
  • Restart the device while the app is running
  • Playing around with airplane mode (doesn't make too much sense)

Then I actually managed reproducing the issue:

  • Writing data into LocalStorage (localStorage.setItem('foo', 'bar'))
  • Remove device battery while app is still running
  • Start device/app and it's gone. localStorage.getItem('foo') => undefined

I ran the next test:

  • Writing data into LocalStorage: localStorage.setItem('foo', 'bar') localStorage.setItem('foo2', 'bar2')
  • Remove device battery while app is still running
  • Start device/app and it's partially gone: localStorage.getItem('foo') => 'bar' localStorage.getItem('foo2') => undefined

So it seems as the last stored item gets lost. Which doesn't make too much sense to me. I tried to figure out where the Android Webview persists the LocalStorage to, to verify if the data is persisted to the file system after a setItem call.

The best thing I could find was this command to access the LocalStorage Log file. adb exec-out run-as com.package.name cat /data/data/com.package.name/app_webview/Default/Local\ Storage/leveldb/000003.log

So every time I did an action like setItem, or after removing the battery I checked the LocalStorage log file directly on the device.

  • After localStorage.setItem('foo', 'bar') => file://...foo...bar was added to the log file.
  • After removing the battery and restart the device => file://...foo...bar was not present any more in the log file.

Summary: LocalStorage loses the last set item when removing the battery while the app is still running.

My current fix would be to always call an additional setItem with the current timestamp, but I really would like to find a proper solution for that.

Questions: How can I check the current persisted LocalStorage Object in the Android file system? Why is this even happening and how do I best fix it?

about 4 years ago · Juan Pablo Isaza
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