【问题标题】:Sqlite Database records are not retrieving when force stopping the Android application强制停止 Android 应用程序时未检索 Sqlite 数据库记录
【发布时间】:2012-03-16 14:26:42
【问题描述】:

我正在使用 Phonegap 1.4.1.js 和 jquery.mobile-1.0.1.min.js 开发 Android 应用程序。我正在使用 openDatabase() 创建 Sqlite 数据库。数据库工作正常。这里的问题是当应用程序在后台运行时,数据库工作正常。如果我手动FORCESTOP应用程序,查询数据库记录是不可能的。但是数据库存在于设备的本地存储中。重新打开应用程序后,即使是 Logcat 也没有显示任何警告或错误。

这是我实现用户登录详细信息的代码:

     function onDeviceReady() 
     {
          CheckLoginData();
     }
     function checkLoginData() {
    var  db = openDatabase("LoginData", "1.0", "LoginData", 200000);    
        db.transaction(queryLoginData, errorLoginData);

}
function queryLoginData(tx) {
    tx.executeSql("SELECT * FROM LoginData where LoginDate='" + InsertCurrentDate + "'", [], querySuccessLoginData, errorLoginData);
}

function querySuccessLoginData(tx, results) {
    // the number of rows returned by the select statement
      console.log("Insert ID = " + results.rows.length); 
      var len = results.rows.length;
      if((len > 0)) {
          var DBdate = results.rows.item(0).LoginDate;
          var date= new Date();
          var month = date.getMonth()+1;
          var day = date.getDate();
          var year = date.getFullYear();
          var systemDate = year+'-'+month+'-'+day;
          //alert(DBdate +  '    '+systemDate);
          if(DBdate==systemDate)
              {
                    //alert(DBdate +  '    '+systemDate);
                    document.location.href = "#recent";
              }
          else
              {
                    alert("Please Login for Today");
                    document.location.href = "#login";
                    $('#useridBox').val('');
                    $('#passwdBox').val('');
              }
        }
        if(len==0){
            var strURL = document.location.href;
            document.location.href = strURL+"#login";
        }
}

function errorLoginData(err) {
     var strURL = document.location.href;
    document.location.href = strURL+"#login"; 
    //alert("Error while Retrieving Data");
}

代码有问题吗。请帮助我如何在强制停止应用程序时获取数据库记录。

【问题讨论】:

    标签: android sqlite cordova


    【解决方案1】:

    我希望您使用最新版本的 phonegap,即 Cordova-1.5.0。 在强制停止应用程序时,Phonegap(使用 webview 提供的默认数据库)中可能存在一些问题。

    我已经修改了 Cordova(https://github.com/Coder-Nasir/incubator-cordova-android),它会在 Android 的默认位置 /data/data/package-name/databases/ 中创建数据库

    只需这个简单的命令

    window.openDatabase("something", "1.0", "PhoneGap Demo", 0);
    

    您将在上述位置获得所需的 something.db..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2020-08-18
      相关资源
      最近更新 更多