I'm trying to use the history as a check to exit the application. The home button reloads the page to google.com, but still retains page history even after I call .clearHistory().
Here is the code for the Menu handling / selections:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.Home:
mWebview.loadUrl("http://google.com");
mWebview.clearHistory();
return true;
case R.id.About:
Toast.makeText(this, "TEXT", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Here is the code for the Exit function:
@Override
public void onBackPressed() {
if (mWebview.canGoBack()) {
mWebview.goBack();
}
else {
super.onBackPressed();
}
}
According to this post you need to call clearHistory when the page finished loading:
It appears that the history clears everything before the current page so if your browser is at page "A", you clear history and navigate to page "B" your history will be "A" "B", not just "B", but if you clear history when "B" finishes loading you will have only "B"
So instead of calling clearHistory
right after loadUrl
, you should envoke it from onPageFinished
or onProcessChanged
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With