How to get Webview's HTML content back on back button click? - android

I am having a Webview with some HTML contains on it. If I click on any url link on that HTML based Webview I am navigated on that url. if there is again any url further I am able to nevigate to that url also. When I click on the back button I am able to get back also. But when I need to get back on the last Webview with HTML contains, it comes back with blank screen, My HTML contains on that Webview are not visiable or present. Can anyone tell me what should I include in my code to get those HTML contains back on Backbutton pressed in Webview.
I am using webview.loadDataWithBaseURL("baseurl", "html_string","text/html","UTF-8",""); to populate my Webview.
Any help will be appreciated. Thanks in advance.

Well I used this WebViewClient Interface
public boolean shouldOverrideUrlLoading(WebView view, String url)
It opens the url of my webview on the local browser of the Device. and when I press back button. it comes back on my HTML based Webpage. Hence no blank page is shown now on comming back on the webview from the URL of the webview.
Thanks to all how commented on this post.

Related

Detect state change in webview

I have loaded a url in webview, when I click on a button a new view appears in the webview without changing the url. Is there any way to capture this state change in the webview?
yeah checkout https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String) using js interface is the only way to register changes in the webview

how to remove webview android programmatically

I am trying to remove webview and recreate webview to load a new html file but i am getting blank page while loading the html url
actually i am initially loading webview on Oncreate() and then i will loading a webpages from different activity that why i am using onActivityResult() to load a new webpage in same webview . The problem is i am getting blank page by using above code but i need to load webpage properly and how?

Android webview sometimes not loading images

I have a simple Activity to show a webview and a back button. Here is the code that I use to load the URL that I want in the webview.
The webpage that I am loading in on a server online, it has a few form elements plus a few links that when clicked I need to keep loading them inside the webview.
Now the problem is very often the page loads without the images, I can see the form elements though or only blank white page. I am testing this on wifi so internet is working fine.
Why is it not loading images and how can I make sure it does? I even tried making all images in the html page have absolute paths, but that did not help.
Later Edit: I found out what was causing this. Maybe others will run into this. I had this in the manifest file android:hardwareAccelerated="true". After removing it the content inside all the webviews is loading smoothly.
Second later edit: It is terrible, I get the initial page load now, but forms are not submitting and after some going back and forward to the webview, new images do not load anymore. Is it a memory problem? How do I make it start fresh every time?
WebView wv = (WebView) findViewById(R.id.webview);
wv.getSettings().setBuiltInZoomControls(false);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient());
wv.loadUrl(filepath);

Android WebView link highlight issue

So I have a html app that I'm loading in a WebView. The thing is I want to use shouldOverrideUrlLoading not to load a specific link, when it gets clicked, so I return true in that method, not loading the url. This works great, but the link is getting highlighted as if it was clicked. Is there a way that I can remove the highlighting if the link was pressed but not loaded?
Thanks
You could have one of a few problems, Clicking on the link in android webview does not get highlighted visually says you have to set Javascript as enabled with:
webView.getSettings().setJavascriptEnabled(true);
There's also been an issue with focus at Android:Webview with link highlight, where you should request focus on your webview with:
webView.requestFocus(View.FOCUS_DOWN);

Android Webview Cache, Not Caching Javascript DOM changes?

Hi I would like to know if there is a way to make the Android Webview cache changes made to the DOM of the loaded page so that when I go back to it, the previously loaded changes remain.
An example would be I'm on page A, call javascript that adds more html content (from an ajax call or w/e), and then I go to Page B. When I hit the back button to go back to page A, page A only displays what the original page load displays.
Is there any quick way around this?
Try this
WebView view = new WebView(this);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
view.clearCache(false);

Categories

Resources