I made an android app with ionic/cordova/sqlite plugin .When I launched the app, the db plugin works well, it open the database and execute sql query as expected. Next I use back button to exit the app and launch it again, I found the db is opened again but I can't execute query with this db, and I can't get the error message. I don't know why. If I remove this app from memory by menu button and launch app again, it works.
The android is 4.2.2. Could anyone know how I could fix it?
my db service:
angular.module('starter.controllers', ['ionic', 'ngCordova'])
.factory( '$h5_dbservice',
[ '$cordovaSQLite','$rootScope',
function( $cordovaSQLite,$rootScope ){
return {
initDB : function() {
db = $cordovaSQLite.openDB( "h5app.db", 1 );
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS tab1 ( ... )'
tx.executeSql('CREATE TABLE IF NOT EXISTS tab2 ( ... )'
tx.executeSql('SELECT count(*) AS cnt FROM tab1 WHERE ...
In my app.js
.run(function($ionicPlatform, $h5_dbservice) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
$h5_dbservice.initDB();
});