Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap how to save permanent data on android

I'm looking for a method to save data permanently using PhoneGap.

  1. LocalStorage
  2. File I/O
  3. ?

I heard LocalStorage is not 100% permanent, but is somewhere in the alley.

I wouldn't really like to begin with File I/O, because what I need is to create a database with recipes, and they need to stay.

"Number 3" is what I'm asking about. Any suggestions?

Thanks in advance :)

like image 690
Daniel Avatar asked Dec 07 '12 10:12

Daniel


2 Answers

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 Phonegap http://docs.phonegap.com/en/2.1.0/cordova_storage_storage.md.html#localStorage

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

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

like image 187
A. Magalhães Avatar answered Oct 23 '22 12:10

A. Magalhães


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/

like image 27
Alex Avatar answered Oct 23 '22 12:10

Alex