I am working on web app which i am using web view to load that directly from website url. At the time of loading that url in android webview it is loading very slowly that it is taking nearly 5 -7 seconds for loading,in the mean while white screen is displaying. So, what i am thinking is while the process of loading webview, i want to display an image on screen and after 5 seconds the app will load. so that by displaying 5 seconds any image in the mean while webview loads so, the user can directly access the app without facing any time delay(like getting white screen).
My code is :
WebView webview = (WebView) findViewById(R.id.webView1);
websetting = webview.getSettings();
websetting.setJavaScriptEnabled(true);
webview.setVerticalScrollBarEnabled(false);
webview.loadUrl("/**here loading my url which is taking nearly 5-8 seconds to load**/");
I tried using splash screen, but here after splash screen has been timed out then webview is loading.
So, can anyone help me with this. Loading of image while webview is loading.
You can cache the image on the disk for each call. Before displaying the image check if the image already exists on the cache. If it does load it from there, else download the image to the cache and load it from there. While the image is loading, show a stub to the user. I've done this with an image view before.
Beware that your cache image may be stale. Your code must handle that too. Here is a related question where this has been implemented
Lazy load of images in ListView
Some of the top answers on that question do not use good coding practices on android so watch out for that.
Related
I developed my own AD SDK (like admob) and use picasso for loading images .
my purpose is prevent user see blank imageview or placeholder while image is loading therefor I want load images in an IntentService to sure when activity started user see image without waiting .
how can i achieve this ?
How to load images in webview as background i.e lazy load images in webview android. Right now while loading a url in my app which uses webview on scrolling images not load instantly which causes UI slide up/down each time any images loads. How can I load images in background with placing a placeholder while the images not loaded.
the webpage which sould be shown, have to provide the dimension of the image. Otherwise you have no chance to guess the dimension for your placeholder. If the dimension is providede. the Webview will automatical reserve the space for the image. (works like any browser)
I am trying to optimize Android WebView loading times for pages, so first thing I need to do is measure the time to display properly as well as total download time. How can I measure how long it takes for the WebView to display the page?
webWebClient.onPageFinished()
is not the right callback because I am seeing the page display at about 3 seconds, but the onPageFinished is called many seconds later depending on the page ... So what is the callback when the WebView actually displays the content that has been downloaded? As opposed to having downloaded ALL of the content?
UPDATE: To clarify I am trying to determine how many seconds to display the content visually. How long before user can scroll etc. NOT how long to download the page completely.
I want to download and load images into Webview as they are downloaded (embedding direct image url's into the HTML is not an option)
When I call the webView.loadData(myData.. the full page is refreshed and the user's app is repositioned to 0,0 - is there a way where I can append to the HTML with the new image as and when it is downloaded? I am looking for a way to override the functionality of resetting the position of the webView on a call to loadData
Thanks
Can you handle the problem in JS side by trigering an event to document when the app has downloaded images ?
Like :
myWebView.loadUrl("javascript:imagesLoaded()");
I use WebView.loadDataWithBaseURL for loading my help page from internal resources of my application.
I have help.html and a few images located in the assets directory. The page loads and shows with images, but the text around image is a mess. It did not show on the right side of the image, instead the image overlaps the text.
This happens only on first loading of the page. If I close the WebView and open it again, then everything is fine.
It seems that at first loading WebView spends some time for loading images and does not reformat page after that. On the second attempt images are cached and displayed together with text and properly formatted.
What is the solution for this problem?
Did anyone face this problem too?
Here is my code:
app.setContentView(R.layout.help);
final WebView web = (WebView) app.findViewById(R.id.helpWebView);
web.setBackgroundColor(0);
web.loadDataWithBaseURL("file:///android_asset/", helpHtml, "text/html", "utf-8", null);
Web page is inside the helpHtml string with the code:
<html><head></head><body><img src="html/flddesc.png" align="left"/>this should be my long long text...</body></html>
P.S: html/flddesc.png is a PNG8 image 180x200 ~20kb of size
Try this function:
webview.loadUrl("file:///android_asset/your_html.html");