I first tried storing data in cookies, and it worked great on my
computer in Firefox, and it works during an active session in Android,
but then when I close the app and re-open it the data doesn't get
saved.
I then saw that people were using HTML5 localStorage, which completely
failed to work for me. After lots of troubleshooting I finally found
that javascript didn't have access to localStorage or to
window.localStorage when running on my phone, but it does when running
in Firefox.
I also kinda tried doing file io and using the HTML sqlite features,
and failed at both of those too. I first tried using phonegap 0.8.0,
and now I'm trying with Edge. It looks like there's an included
storage.js file that deals with the HTML5 sqlite databases, but I
haven't gotten it to work yet.
Is there any simple way to store persistent data with PhoneGap for
Android? There aren't any tutorials on the wiki about it (there's one
that explains how to use SQLite for iPhone, but I couldn't get it
working for Android). I can even make just simple key/value pairs work
for my app, although a SQL database would be better because I will be
dealing with lots of data.
Thanks!
Micah
Android 2.0+ has many HTML 5 local storage options, one of which is
the use of window.openDatabase, which allows you to create sqlite
databases. There are plenty of tutorials on how to use this:
http://www.google.ca/search?hl=en&q=html5+openDatabase
The only caveat with instantiating a database from JavaScript in
PhoneGap Android is that the initial size of the database that you
specify via the last parameter to the openDatabase call must be less
than the allowable size of the database on the native end. This
maximum size is set in the native code, in DroidGap.java under the
EclaiClient private class as a constant:
private long MAX_QUOTA = 2000000
So, you have to make sure the size parameter you pass in is less than
2 million (this is bytes, so maximum size of your database is
1,999,999 bytes). You can of course change this (I think?), just make
the appropriate change in the native code.
Hope that helps,
Fil Maj
Web Software Engineer
Nitobi
Now I need to figure out how to preload the sqlite database with my
own database in Android...
Micah
It's for iPhone, but answers the same question, and perhaps a similar
strategy could be used for Android...
Let me know if you undertake it and how it goes!
Cheers,
Fil Maj
Web Software Engineer
Nitobi