2

Im using localStorage(Key-value pairs) for saving the data in my Cordova app. Is there any way to clear the app's localStorage programmatically. One way is to clear the App's Data in Application Manager Settings, But i want to Clear the localStorage programmatically. Instead of using the Clear Data , I'm using ManageSpaceActivity(http://developer.android.com/guide/topics/manifest/application-element.html) in my application . Once the Manage Space button is clicked , I have to clear the localstorage. The problem is I don't have WebView instance in ManageSpaceActivity

Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55
  • try the normal javascript way -- localStorage.clear(); – Tasos Mar 29 '16 at 03:12
  • Instead of using the Clear Data , I'm using ManageSpaceActivity(http://developer.android.com/guide/topics/manifest/application-element.html) in my application . Once the Manage Space button is clicked , I have to clear the storage. – Sasank Sunkavalli Mar 29 '16 at 03:17

3 Answers3

1

Either you can use

window.localstorage.clear();

or

window.localstorage.setItem("key","");

first 1 will clear all of the localstorage and second 1 will set blank for specific key.

1

For this, first you have to find which platform you are..for this read more for this plugin

By this command you will get to know which device you are using

var string = device.platform;

When you will get on which platform you are, you can start working towards.

To clear localStorage of Android platform, use this

localStorage.clear();

For more detail about this, read here

Community
  • 1
  • 1
Kishore Vaishnav
  • 510
  • 3
  • 17
0

As far as my requirement is concerned , I want to share the localStorage across all Webviews of the app. LocalStorage is partially broken in Android webviews : Local storage is supposed to be a persistent storage available across all tabs (or windows) of a browser. On Android, LocalStorage works well but only in the current webview. Multiple webviews of the same app can't share the same data with LocalStorage. The only way of working around is to use to getFilesDir() & go to the Parent Directory . Then search for the folder /app_webview/Local Storage/ & delete it , So that app's localStorage will be deleted.

All the localStorage that we use in the App's Webview will be stored under the folder /app_webview/Local Storage/ .

Useful Links:
1) share localStorage across webView and CordovaWebView android

2) https://github.com/didimoo/AndroidLocalStorage

Community
  • 1
  • 1
Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55