刚刚将我的 android 应用程序更新到 Cordova 2.5,虽然它在模拟器中运行良好,但它在我的 HTC 愿望上产生了一个问题,以至于我在尝试时收到“未定义”数据库错误
db = window.openDatabase("ProblemDirectoryDB", "1.0", "PhoneGap Demo", 100000);
但是,如果我第二次打开同一个页面,它就可以正常工作,从那时起,即使在强制停止并重新启动之后也是如此。我可以通过删除应用程序的数据来重新创建错误。相关代码如下。非常感激地收到任何帮助/想法。
var db;
var dbCreated = false;
function onBodyLoad(){
$.mobile.loadingMessageTextVisible = true;
$.mobile.loadingMessage = "Loading...";
$.mobile.showPageLoadingMsg();
if (!window.device){
document.addEventListener("deviceready", onDeviceReady, false);
}
else {
onDeviceReady();
}
}
function onDeviceReady() {
db = window.openDatabase("ProblemDirectoryDB", "1.0", "PhoneGap Demo", 100000);
if (dbCreated){
db.transaction(getProblems, read_transaction_error);
}
else{
db.transaction(populateDB, create_transaction_error, populateDB_success);
}
navigator.splashscreen.hide();
}
function populateDB_success() {
dbCreated = true;
db.transaction(getProblems, transaction_error);
}
function create_transaction_error(tx, error) {
$.mobile.hidePageLoadingMsg();
alert("Create Database Error: " + error);
}