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.
Related
I'm trying to replicate the functionality of Facebook's image upload. To briefly describe it you click the Photo button from the main screen of the app you are taken to an image picker that will let you select up to 30 images. Once selected the images load in some kind of list view that allows you to add a caption, remove the image from the list, or do some other Facebook-y things. If you scroll around the list can move very quickly, and if you only have 5-10 images you generally spend little to no time waiting for items to reload.
Right now I have a recycler view and am using Picasso to load the images from disk, resize them, and then display them. This works, but it's not smooth or fast. Even if I only have five or six images loaded they don't come up instantly if I scroll from the bottom back to the top. I have tried increasing the LRU Cache size in Picasso, but that didn't do anything at all. It seems like the scaled image isn't getting cached so it has to be scaled to fit the screen width every time. That's just my guess though.
Any suggestions on how to get this to run more smoothly?
I am bulding up a grid of images for an app I'm building. It works like so:
Build up a list of Image IDs, which I must query using a different content provider each (these are images from MMS threads)
Create new activity, which hosts an ImageGridFragment. This fragment has a custom adapter that takes the grid of images, and loads each one as a bitmap asynchronously.
After images are loaded, they are cached in an LRU cache so I don't need to run unnecessary computation
So far, everything works quite well. However, I would like to pre-buffer images so that when the user scrolls down, s/he doesn't have to wait for images to load. They should already be loaded. The stock Android Gallery accomplishes. I've had a look at the source, but think there must be a more straightforward way.
To answer members' questions
Images are loaded one by one using the content://mms/part/xxx, where xxx is the ID of an image. These are MMS images, and to my knowledge, cannot be loaded as a batch process (though, maybe I'm wrong). I use a content provider in an AsyncTask to load each image
I've tried the following:
Pre buffer 30 images or so right when the fragment is created. This is not ideal because the massive I/O request, actually prevents the on-screen images from loading quickly (but the buffering does work well!)
Detect when the requested view to load is at the very bottom-right hand corner of the screen, which could work, but then would fail in the case that the GridView takes up only part of the screen. It also seems like there should be a cleaner way to do this
Thought about, but did not try, an OnScrollListener, but this will not pre-buffer images until I start scrolling, which is not ideal
So, my questions are:
Is there a good way to detect when the last GridView item is requested to load? I found that the GridView.getlastvisibleposition() method is not useful here, because it is actually returning the last element for which Adapter.getView() has been called for. If I can do this accurately, I can launch the buffer request at that time
Is there a better way to do this?
you can do right this
if(GridView.getlastvisibleposition() = mAdapter.count()-1)
how you load the images?
is it from URL or from sdcard?
are you using a image loader library?
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.
i have a gles based game that takes quite some time to load because of the huge amount of textures.
now i want to display a loading-text or loading-bar as soon as possible as the application is starting up.
what is the fastest way to display a text like this? should i do it in gles as well or should i use an alert or view?
I made a separate loading screen activity in my game that uses the standard Android UI. It has a text view saying "Loading" and a ProgressBar that gets incremented as it loads in images, sounds, etc. from disk into memory (I put all filenames into a stack and then pop them off one at a time and increment the ProgressBar after I pop something off the stack). When the loading is done, it takes the user to a main menu activity, and from there they can start my game.
In android mobile we have an default application Market, under submenu there is functionality called all applications. In this, first it shows only ten records in which it will display defalut image and text, then in back ground it will update images. When we scroll down (i.e., end of list) and it shows loading and then it loads next 10, images will load lazily.
How to acheive this senario.
Thanks in Adavance
Jayanth
In this, first it shows only ten
records in which it will display
defalut image and text, then in back
ground it will update images.
I have done this with my ThumbnailAdapter, though I want to rewrite it sometime in the next few months.
When we scroll down (i.e., end of
list) and it shows loading and then it
loads next 10, images will load
lazily.
I have done this with my EndlessAdapter.
Perhaps these will give you some ideas.