3

I want to clear localStorage for my app each time I install it from Eclipse to simulate installing the app for the first time.

How can I do this?

Thanks!

I answered this, specifically for Android, here - Programmatically clear PhoneGap/Cordova app's cache on Android to simulate a fresh install?

Community
  • 1
  • 1
Jasper Mogg
  • 924
  • 2
  • 8
  • 23

4 Answers4

3

There are no hooks in Eclipse, but you could probably do this with Ant. You can add a task that executes the clear command (pm clear my.package) before uploading the app. If pm clear does not work, you can write a small script and start it on the device before uploading the app

There is also the Android run configuration's 'Wipe user data' checkbox, but it only works on emulator startup.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • Unfortunately that only seems to clear the emulator on startup, rather than on each app run... – Jasper Mogg Jun 22 '12 at 10:38
  • Right, now I remember :) There are no hooks in Eclipse, so you could probably try running with Ant, that will let you execute commands before uploading the app. Does `pm clear` work for you? If not, you can write a small script and start it on the device before uploading the app. – Nikolay Elenkov Jun 22 '12 at 13:22
  • It does work, yeah. I just don't know how to do what you're describing. I'll have a look at ant. If you edit your post to this effect I'll accept it. – Jasper Mogg Jun 22 '12 at 13:27
2

I'm using Chrome inspector (chrome://inspect) which very nicely shows the connected Android device. From there you can just hit Resources to access and modify the localStorage

Joshua Ohana
  • 5,613
  • 12
  • 56
  • 112
0

I am not sure if you want it programmatically or via ADB - in any case this should solve it

How to programmatically clear application data

Community
  • 1
  • 1
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
0

For testing purposes, you can drop a quick local storage clear statement:

localStorage = ""

Make sure to remove this before release.

Zorayr
  • 23,770
  • 8
  • 136
  • 129
  • If you were using the database, rather than localStorage, this wouldn't work. I answered this question here in the end - http://stackoverflow.com/questions/11159280/programatically-clear-phonegap-cordova-apps-cache-on-android-to-simulate-a-fres – Jasper Mogg Jun 22 '12 at 17:40
  • *Where* do you drop this statement? – ADTC Aug 19 '14 at 06:46
  • The line is in JavaScript, so anywhere that you're running JavaScript. – Zorayr Aug 21 '14 at 01:22