I am having one activty, in which Webview is available. If I click on any URL in the webview, that url opens, but when I click the back button, it doesn't comes on the previous Webview page, but goes on the activity which is before that webview page.
Scenerio:- I am having a Xyz Activity, on some element of Xyz activity click it goes to a Webview activity which shows the loaded url on webview. on webview if I click on any url link, it opens, but when I click the back button, it goes back on the Xyz Activity and not on the Webview Activity. I want to come back on the Webview Activity and not on the Xyz Activity.
Can anyone Guide me for the same, as I am not able to find what should I use or implement for making it work as I need? Any help will be appreciated. Thanks in Advance...
EDit:-
The code is as follows:-
public class StoryDetail extends SherlockActivity
{
WebView content;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.story_detail);
BaseStory story = BaseStory.createFromCursor(c); // BaseStory is a class containing Database values...
// Get the fields
content = (WebView) findViewById(R.id.content);
content.getSettings().setPluginState(PluginState.ON_DEMAND);
content.getSettings().setJavaScriptEnabled(true);
content.getSettings().setAllowFileAccess(true);
content.setWebChromeClient(new WebChromeClient());
content.setWebViewClient(new WebViewClient());
String html =
"<html><head>" +
"</head>" +
"<body>" +
"<section id=\"content\">" +
story.getContent() +
"</section>" +
"</body></html>"; //story.getContent() contains title, image, and url link supporting HTML Format itself.
//On clicking url link the webview open that page in Webview.
content.loadDataWithBaseURL("http://somelink/", html, "text/html", "UTF-8", "");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(content.canGoBack()){
content.goBack();
}else{
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}