簡體   English   中英

Android Webview中的后退按鈕問題

[英]Back Button Issue in Android Webview

問題很難傳達,實際情況將幫助您理解真正的問題。

在Android應用程序中。

我有很多Jquery Mobile Page附加到android Webview。

當我選擇一個頁面(例如)配置文件時,頁面會正確打開,如果我按“后退”按鈕,則應用程序將移至主頁;如果再次選擇配置文件並按回,則應用程序將進入登錄頁面。

如果我選擇其他頁面並選擇配置文件,則不會發生。 此問題不僅與單個頁面有關。 在所有頁面中,我都有相同的問題。 有人可以指導我該怎么辦嗎?

按鍵事件的源代碼,在此處輸入代碼

   @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && webview.isEnabled()
            && !this.onLogin) {

        webview.loadUrl("javascript:handleDeviceBack()");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK && this.onLogin) {
        moveTaskToBack(true);
    }
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        webview.loadUrl("javascript:handleDeviceHome()");
        return true;
    }
    return false;
}

在我的網絡視圖中

enter code here
 handleDeviceBack = function(status) {
mHealth.util.logMessage('On device Back');
var historyBack = {
    "home" : "page",
    "loginPage" : "page",
    "welcomeMsg" : "page"
};
var moduleIndex = {
    "assessNotFound" : "../../home/view/home.html",
    "showActivity" : "../../home/view/home.html",
    "showMessage" : "../../home/view/home.html",
    "show_tracker" : "../../home/view/home.html",
    "settingsPage" : "../../home/view/home.html"
};
var graphPages = {
    "singlehealthdatapage" : "page",
    "multiplehealthdatapage" : "page"
};
var otherShortcuts = {
    "show_tracker_view" : "../../trackers/view/showtracker.html",
    "detailMessage" : "../../messages/view/showmessage.html",
    "alfrescoDIV" : "../../messages/view/showmessage.html"
};
// var exitAppCriteria={ "home" : "page","loginPage" : "page","welcomeMsg" :
// "page"};

if($('.ui-page-active').attr('id')=="condition_index")
    {
        $.mobile.changePage("../../home/view/history.html");
    }
else if (historyBack[$('.ui-page-active').attr('id')]
        || $('body').children().is('#tandcPage')) {
    Android.finishActivity();
} else if (moduleIndex[$('.ui-page-active').attr('id')]) {
    Android.highlightHome();
    $('.ui-alert-wallpaper').detach();
    $.mobile.changePage(moduleIndex[$('.ui-page-active').attr('id')]);

} else if (graphPages[$('.ui-page-active').attr('id')]) {
    Android.showTab();
    Android.pageHistory();
} else if (otherShortcuts[$('.ui-page-active').attr('id')]) {
    $.mobile.changePage(otherShortcuts[$('.ui-page-active').attr('id')]);
} else {

    $('.dw').detach();
    $('.dwo').detach();
    $('.dw').detach();
    $('.ui-alert-wallpaper').detach();
    Android.showTab();
    Android.pageHistory();
}

};

我發現問題出在Android.pageHistory();

enter code here
    public void pageHistory() {
    this.activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            WebContainerActivity.webview.goBack();

        }
    });

}

第一次運行正常,但如果函數反復調用web view.go,則返回第一頁。

在您的活動中覆蓋像這樣的backpressed方法

  @Override
    public void onBackPressed() {
      webview.loadUrl(sameurl);
        }

通過其ID對URL進行硬編碼,並暫時解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM