【发布时间】: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");
}
代码有问题吗。请帮助我如何在强制停止应用程序时获取数据库记录。
【问题讨论】: