2012-09-17 64 views
0

問題很難傳達,實際情況將幫助你們瞭解真正的問題。Android Webview中的後退按鈕問題

在Android應用程序中。

我有很多JQuery的手機頁面附加到Android Web視圖。

當我選擇一個頁面(例如)配置文件時,頁面可以正常打開,如果我按下後退按鈕,應用程序將移動到主頁面,如果我再次選擇配置文件並按回應用程序進入登錄頁面。

如果我選擇一些其他頁面並選擇該配置文件沒有發生。這個問題不僅僅是單個頁面。在所有的頁面我都有同樣的問題。有人能指導我該怎麼做?

重點新聞事件的源代碼, 輸入代碼在這裏

@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回到第一頁。

+1

你的目標是什麼?你想做什麼?什麼是必須的? – magirtopcu

+0

即使在我從特定頁面按下設備返回按鈕的時候,也應該始終訪問同一頁面。我粘貼代碼以便我們可以瞭解確切問題的一些圖片。 – Jabeer

回答

0

很難得他們的ID編碼的URL,並暫時解決了這個問題。

1

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

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

沒有幸運,發生同樣的問題。這個問題是當我們按下後退按鈕兩次時,應用程序返回到第一頁。 – Jabeer