Phonegap how to save permanent data on android Phonegap how to save permanent data on android database database

Phonegap how to save permanent data on android


I'm using the localstorage and this is the best solution to keep saved data. Like you said, it isn't 100% permanent. In my case the localstorage is cleared only if you uninstall the app. Find more info about localstorage with Phonegaphttp://docs.phonegap.com/en/2.1.0/cordova_storage_storage.md.html#localStorage

You could get more info about localstorage onhttp://diveintohtml5.info/storage.html

You could use a database as well. You can find info on this athttp://docs.phonegap.com/en/2.1.0/cordova_storage_storage.md.html#openDatabase


If you would like to store the data on the device permanently even after the app in uninstalled, you will have to do it in a different way on iOS and android.

On iOS you can use the keychain https://github.com/shazron/KeychainPlugin.

On Android you can use the file plugin, and store the data on the SD card (cordova.file.externalRootDirectory).

In both cases, the data will remain on the device even if the user re-installs the app.

If you are using ionic (or just angular), you can use ng-persist that wraps these two plugins in an angular service with the same API for both ios and android.

More details here http://alexdisler.com/2014/04/23/persist-data-mobile-device-app-removed-uninstalled-cordova-ionic/


You could do the following steps for saving any data permanently,

  1. Your HTML file

    <div id="deviceready">

    <div id="result"></div>

    </div>

  2. You JS file

    window.onload = function(){    document.addEventListener("deviceready", init, false);}function init(){ document.getElementById("signin").addEventListener("submit",login, false);}function saveData(){  window.localStorage.setItem("header", 'Some Text Here');}function getData(){      document.getElementById("result").innerHTML =      window.localStorage.getItem("header");  }}