I have a scenario where on a page I can have multiple WebViews that can dynamically load, all at the same time. For example the user may have defined a Google and Yahoo link on the same page. All fine and dandy. What I need though is a way to show that a web view is being loaded without the standard Loading progress dialog since that will freeze the screen. Rather I would like to either show an image in the web view itself saying the web view is loading or have an indicator INSIDE the webview that does not affect the users ability to add data in case the loading of the multiple web views takes a while.
I attempted to load an image in the web view(s) just before loading the real urls, but it seems to either be ignored or immediately overwritten.
thanks!
Related
In my application am showing contents with URL www.domain_name.com/content?id=5513 . Each content have different ids. When phone have data then it loads WebView from network, otherwise it loads from cache. My issue is that webview loads partially for every URL.
It was backend issue, where pages are loading dynamically to single page. Changed dynamic page to single page.
I am working on an android app that displays Web Content that it obtains from a Web site. The app obtains this content from a Web page. The problem is I want to display a particular portion of the Web page, not the whole thing as the whole thing contains excess unwanted content. How can I display the data I need?
you need to download HTML code without WebView first. Then process it removing unwanted data, and then load resulting HTML into WebView
I'm trying to load a url in webview in android. The url loads fine in the web view. But the problem is the loading time of the webpage in the webview. Sometimes the webpages loads instantly within 1-2 seconds. But sometimes, the web page takes more than 40 seconds to load the webpage in the web view. When I checked the url on the browser, it loads within or less than 2 seconds. The problem is that when the web page takes more than 2 seconds, the white color of the webview is only showing and the users are thinking that the app is stuck or not responding. So they are complaining about the loading time. Is there any way to rectify this problem.
The best way to load content coming from internet is to use separate processes than the main one.
An example is:
you click to open the webview;
the app doesn't launch the webview activity but a splash screen with the "Loading..." information (plus a logo or an icon);
this splashscreen activity verifies if the internet connection is
available; if so, the splash activity launch an AsyncTask which, in a
separate backgorund thread, download the necessary HTML page (or XML file, etc);
when the content is correctly downloaded, the splash activity calls
the Webview activity, giving the necessary data trough an Intent.
This way is commonly used to load internet content on apps; it allows the operator to don't see a freezed activity but a window which suggest that a process is on-going.
Please find here the official information regarding AsyncTask.
A classic example which uses the SplashScreen/AsyncTask/BackgroundProcess is a RSS Reader; please find here a source code which can help you to understand (check out the SplashScreenActivity).
This is one way to do it, but it's not the only one.
I had similar problem on Android 4.4 version. This worked for me
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
It is due to some bug in webview for Kitkat version.
I'm making an app where the main content that te user wants to view is in the form of html pages, I'm actually porting an app over from iphone and want to reuse the pages because there are 100 of them and recreating them as android layouts would be quite time consuming. The problem is that on android the webview takes about 4-5 seconds to load the first time I open a page and a couple seconds each subsequent time.
I searched and found a similar answer but don't know if it will work for my situation(preload webview). This answer suggests using a viewflipper with multiple webviews already loaded so when you switch between them it is instantly loaded. I don't know if that will work for me because I have 100 different pages to cache(Although I could optimize it down to about 30 max by only loading ones the user can navigate to from their current page) and because the webviews are in a different activity than the button the user clicks to view the page. i.e the user is looking at a listview with about 30 different options for pages to view, when they click a listview entry it opens the activity with the webview and I would have to wait until the user made that click to begin loading the webviews, so theres no way to shave off any loading time there.
I suppose since the listview and webview activities are the same, just a small view for the title then either the webview or the list underneath of it, I could consolidate into one activity and have the listview as well as all the webviews in the view flipper and the only thing I would lose is the transition between the listview activity and the webview one, which is not a big deal. Would this solution work? Should I really just cache up to 30 webview pages? I don't think this is a viable solution and I want to ask if anyone who is better than me with android programming has a better solution. If I could preload just one page that would be enough, although not optimal, because it only takes a couple seconds to load the 2nd 3rd 4th etc... pages.
tl:dr - webview takes 5 seconds to load the first page and a couple for each one after that. I wan't to make it instant but if that isn't possible i want to at least preload the first one(idk which html page to load until the user actually clicks an option btw, and there are 100 different options) so it doesn't take 5 seconds. Right now I'm looking at finding a way to preload/cache up to 30 pages so all the users options are already loaded but that might use to much memory. Also considering finding a way to open the activity in the background and load the webview with whatever page, doesnt matter, just to get through the initial 5 second load time.
Sorry I actually had trouble wording this well for some reason, I hope you can follow what I'm trying to do. Thanks
Oh BTW - all of the html is stored locally in my assets folder and I'm using webView.loadUrl("file:///android_asset/About cards.html"); etc to load the pages
Is there any way to make a call to the Android web browser, that ships with every phone, to render a web page and return it to my program as an image?
This would be hidden from the user. It would not command the Android browser to open itself up on the user's screen and display that web page. Instead, it would be feeding my program rendered web pages as images, and the user would only see my program and not the Android browser.
Thank you.
You don't need to use the system browser, the HTML rendering capabilities are available by the WebView class. It also has a method WebView.capturePicture(), which you can use to obtain an image of the whole rendered website.
However, it could be tricky to drive the WebView into rendering the web page while it is not visible. It must be attached as some view to the current Activity to start loading pages and render them, however its maybe possible to have it hidden in the background when attaching more than one view to a container view like ViewGroup.