I have a application as below that runs as FullScreen.NoTitleBar:
public class BrowserActivity extends Activity {
private String lastUrl = "http://www.google.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setSupportMultipleWindows(false);
settings.setSupportZoom(false);
settings.setPluginsEnabled(true);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
lastUrl = url;
view.loadUrl(url);
return true;
}
});
web.setVerticalScrollBarEnabled(false);
web.setHorizontalScrollBarEnabled(false);
web.loadUrl(lastUrl);
}
}
The “lastUrl” is used for handle orientation changes and let the user on the same page that he was while navigating.
But my problem is, if the user follow some links then hit the return button, the application just closes instead of returning a page back. How can I handle it?
I solved it by handling returns and keeping track of the URLs visited by the user.