我使用phonegap。我想从
调用JavaScript方法android中的onResume()
方法。我总是在onResume()方法中看到日志消息,但有时会调用JavaScript方法,但有时不调用,而且JavaScript方法调用很晚!我不知道为什么!怎么解决这个?
感谢您的建议
编辑:添加代码段:
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (AppConstants.firsRunApp) {
AppConstants.firsRunApp=false;
if (!DetectGPSTurnOn()) {
this.sendJavascript("javascript:showDialog()");
} else {
gpsEnable();
}
// checkGPSEnable();
checkNetworkIsEnable();
}
if (AppConstants.TAG_TESTAPP) {
Log.e(AppConstants.TAG_FOR_TEST_APP, "onResume");
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if (!firstRun) {
turnOffGPS();
}
firstRun = false;
if (AppConstants.TAG_TESTAPP) {
Log.e(AppConstants.TAG_FOR_TEST_APP, "onPause");
}
}
JS sid:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function showDialog() {
console.log("doConfirm method");
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text("enable gps");
confirmBox.find(".yes,.no").unbind().click(function () {
confirmBox.hide();
});
confirmBox.find(".yes").click(function yes(){Request("TurnOnGPS","turnOnGPSMet",null);});
confirmBox.find(".no").click(function no(){});
confirmBox.show();
}
</script>
</head>