I am having trouble in Android WebView trying to return to the previous page and reload that previous page's URL to show the updated page.
I have tried using myWebView.goBack() followed by myWebView.reload(), but for some reason when I do that it just keeps loading the current page everytime I press the back button. My guess is that somehow myWebView.reload() is called before the WebView goes back to the previous page, hence it keeps reloading the current page's URL.
I have not been able to find an answer after lots of searching, but if anyone does in fact know of a page with an answer I would be grateful if you could link me to it.
This is what my code looks like where I tried to implement the goBack() and reload() methods.
@Override
public void onBackPressed(){
if(myWebView.canGoBack()){
myWebView.goBack();
myWebView.reload();
}
else{
if(doubleBackToExitPressedOnce){
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please press back again to exit", Toast.LENGTH_SHORT).show();
mHandler.postDelayed(mRunnable, 2000);
}
}
The part with doubleBackToExitPressedOnce is used to get the user to press back twice before exiting the app if they can not go back to a previous page any further.