Closing the database in a phone stutter

In my phonegap app, I got this error.

[INFO:CONSOLE(0)] "forcibly closing database"

      

that I have in my project trying to access the database in a plugin (background service plugin) this is causing the problem.

I used this Background Service Plugin worked well on nexus devices but not on Samsung devices

How to solve this problem. Sample code:

function selectUser() {

var query = " userid,islogged FROM user where islogged=1";
transactionSelect(query,"login");
}

function transactionSelect(query,str){
db = window.openDatabase(DATABASE_NAME, DATABASE_VERSION, DATABASE_NAME, 10000000);

newStr = str;

db.transaction(
         function(tx){
             tx.executeSql("SELECT "+query,[],returnExistingUser,noDBError);
 });
}

// query returns success


function returnExistingUser(results){
//alert(JSON.stringify(results));

if (results.rows.length == 0) {
    window.location.hash = "#loginpage";

} else {
    userName = results.rows.item(0).userid;
    // background service called here
    getServiceStatus();
    storeObject.userId = "userId";
    if(device.model == "SM-T331" || device.model == "SM-T210" || device.model == "SM-T111" || device.model == "SM-T110"){
        setTimeout(function(){
            window.location.hash = "#viewpage";
        },4000);
    }else{
        window.location.hash = "#viewpage";
    }
}
$.mobile.autoInitialize();
}

      

in the service (plugin)

public void getLoggedUser() {

     String sqlQuery = "SELECT userid FROM user WHERE islogged=1";
        Cursor cursor = db.rawQuery(sqlQuery, null);

        if (cursor != null && cursor.getCount() > 0){
            cursor.moveToFirst();
            do {
                username = cursor.getString(0);
            }while(cursor.moveToNext());
            Log.e("uname", username);
            if(username != null){
                //here another query will e exec
                getOrders(username);
            }
        }else{
            //Log.e("no data", "no data");
            db.close();
        }
}

      

+3


source to share





All Articles