cordovaSQLite Database not persistent on actual device, works in the emulator


#1

I have written a basic note-taking application, using the cordovaSQLite plugin.
The application works perfectly on the Genymotion emulator, the data is persistent and is showing up even on restarting the emulator.
However, it doesn’t look like the database is being saved on my actual phone.
When I restart the application on my phone, no older notes are being loaded.
They are being loaded on the emulator, but not on the actual phone.

Attached is the link to the app.js file in my Github repo.

Thank you.


#2

Maybe the problem is in your index.html file.

Try to remove the ng-app=“app” from body tag and add before the the lines:

<script type="text/javascript">
        document.addEventListener('deviceready', function onDeviceReady() {
        angular.bootstrap(document, ['app']);
        }, false);
</script>

#3

That didn’t seem to work…
If it helps, here is the console log from chrome://inspect/#devices that I use to view the console while the application is running on my device.
OPEN database: notesDB SQLitePlugin.js:175 (3) new transaction is waiting for open operation SQLitePlugin.js:106 DB opened: notesDB SQLitePlugin.js:80


#4

Seems something that lock the db on android, maybe you can found help here: https://github.com/litehelpers/Cordova-sqlite-storage

Try to add: androidLockWorkaround: 1 in the openDB function call.


#5

That didn’t work either.

The console shows the following errors:

OPEN database: notesDB SQLitePlugin.js:175 (3) new transaction is waiting for open operation SQLitePlugin.js:106 DB opened: notesDB SQLitePlugin.js:80
But it still works fine on the emulator. Maybe these errors stop execution on the actual device?


#6

If you can, try to use native sql instead sqliteplugin and see what happens, use: window.openDatabase