My application consists of tablayout with webview in each tab. There are two ways of loading offline content one is loading local pages & the other is caching. I am currently using caching , however which is faster ? Is loading local pages obsolete or redundant ?
For example when the webpage loading is complete I want to save it in
when I swipe from one tab to the other , no matter what I do the webpage will reload. I just want it to be blistering click just like viewing photos in a photo gallery.I tried almost everything and finally want to check loading local pages i.e when the user will navigate to different pages a local page will load.
Will it make any difference ?
Related
I am currently working on android webview applications. I was wondering if there is a way to load selected pages only in android webview, like just tell the app to load only specific pages,not whole website. Is it possible?
Depends on what you mean by specific pages. You can lock the webview into only a set of URLs by overriding shouldOverrideUrlLoading to return true and just not load any URLs you don't want to. If you mean you want to not load part of a URL I don't think there's a way to do that.
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 want to be able to swipe between many HTML pages without noticeable lag. To do this, I want to load all of the pages into separate WebViews either in the background after the app is loaded, or in onCreate(). I'm using the code here: Looking for Android ViewFlipper Example with Multiple WebViews but ran into errors trying to create WebViews in doInBackground(), something to do with needing to create WebViews in the main thread. So instead, I just created the WebViews in onCreate().
However, this example uses just three HTML pages. I want to load up to 300. What's the best way to do this other than hard-coding 300 WebView objects?
You should reconsider why you need to do this, it is never a good idea to cache this many objects into memory. Chances are the user will never move through all 300 pages during one session so you will have wasted resources loading many unnecessary WebViews.
If you need to load Webviews without lag you should look into using ViewPager. It is perfectly suited for your needs and the Android developer site has a tutorial for exactly what you are trying to accomplish here.
ViewPager even allows you to set how many pages it will cache at a time. If you need to preload pages you can use the setOffscreenPageLimit method to set how many pages should be loaded ahead of time.
You can load the HTML/DATA before you load it into the webview, so at least it doesn't have to go to the network to get the content
Also, you can set how far away from the current index the ViewPager will load
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
I want to create a main menu with a gallery that gets images from my website.
and shows them in the gallery for a user to scroll through and see upcoming event pictures.
The images will change just about every month. What is the best way to go about achieving this?
I was thinking maybe storing the images in a particular directory and having a URL set to the image.
The only question is... What happens when the images change? How would i go about updating the URL in the application? No way right?
Another thing... When the images are scrolled off the screen how do we make these images where they wont reload when out of view, causing unnecessary use of bandwidth and possibly outofmemory error.
So from what i have discovered so far, What is the best way a
You could store the urls in a database, have the app download a small text file upon launch containing the newest urls. if there is a difference, then download the new images and update the links in the database.