Reputation: 1370
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.
Upvotes: 2
Views: 1678
Reputation: 11185
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.
Upvotes: 1