Prefetch & cache dynamically created jqueryMobile+PhoneGap pages - android

I have a PhoneGap app (with jqueryMobile) which uses several listviews, sometimes with pictures included.
On some devices this can take 1-2 seconds to load. I have tried to use the cache-
<div data-role="page" class="listpage" data-dom-cache="true">
and prefetch-
<a href="listview_1.html" rel="external" data-prefetch>Listview 1</a>
options, but neither would work / make any difference.
The pages are almost completely dynamically created from a sqlite database - maybe this is the actual issue...?
Any hints greatly appreciated, Thanks!

I think cache will not solve your problem. cache stores temporarily pages and images, and also mainly for second time load only. Other choice is reduce the list view count for example 8 or 10 with load more button or scroll to append new list values use pagination concept to load list view. If your using cache concept you can't load new list values so that's not dynamic list view.
Best choice for cache is list view to navigate detailed view. Because after user clicks back button or link to retain list view.

Related

Android Webview Performance improvement by caching

I am working on and Android app which has legacy code and we are using ListView and optimizing the listview by using ViewHolder.
Our listview has different types of custom views which are a bit complext. The scrolling performance of the listview is pretty good till now.
A new requirement has come up to support Webviews in the same listview. The webview content to be loaded from disk and javascript is enabled.
The problem is that when I add webviews in list the scrolling become jittery. During the scrolling I can see that the webview content is blank as it is still to be loaded.
I think the performance degradation is due to two reasons.
1) creation+Loading of new Webviews everytime getView of listview adapter is called
2) Displaying the content of webview
To solve these issues I started caching 7 webviews and I am recycling the webviews by detaching from previous parent view and attaching to new parent view. For example if the current visible item index is 5. I will also create the webview for three next(6,7,8) and three prev(2,3,4) items and keep them in a cache based on some id of listview item content. So when there is requirement for next item say for index 6, I will simply return one item from cache and update the both from front and back to hold 3,4,5 and 7,8,9 index items.
I was thinking that by creating a pool of webviews I will solve both the problems. 1) creating new webview ever time getview is called. And by prefetching the next/prev 3-3 items I can preload url so display will happen in background.
But I can see that display is still taking time and scrolling is still jittery.
So my questions are:-
Does webview display the content only when it is attach to a window ? (In my case the webviews in caches are not attached to window and I am loading the url in them.)
Does webview display the content only when it is visible ?
Is there a way to render the content of webview in background so that by creating cache of Webview I can do smooth scrolling.

How to perform a long task by breaking it into sub parts and get the results using the sub parts in android

I am implementing an ebook reader for android. I have done the pagination part successfully. But it takes a long time to load the book. what I did was, get the raw html and break into chapters and store them in a array. Then get the entire string and using Html.fromHtml I removed the html tags (because I am using view pager and need to get the no of pages, for this reason we need to remove the unnecessary strings first). Then according to this answer I am breaking into pages. (The logic was to get a sub string and check the string height is greater than the screen height, I am checking this condition at every space in the string).
I have used epub-lib library and jsoup for this project. I am using dynamic textviews and Imageviews for this.
Now I need to optimize this process. How to do this? My idea is to load and show the initial pages to users and while the user going through them the rest of the content should be paginated and loaded using a background process.
Is this possible? I am happy to get any other suggestions as well.
Thanks
Yes that should be possible. I had a similar situation where I had a ListView that potentially listed thousands of items from a database. Instead of loading everything, I simply read the first 9 items, displayed them and then had a listener for when the scrolling had reached the bottom of the list and then updated my listview to include the next 9 items.
Also, from a performance perspective, if your book is very large, I'd suggest doing that sort of parsing work immediately after you've downloaded the file in an AsyncTask. I would break down the pages of the book into different objects (i.e. page 1, 2, 3 in a "page" object) and then when you need to display that page, you simply read and display that object. This would also be beneficial if the user opens the ebook multiple times, as you won't have to parse the entire html file again each time that ebook is opened.
The logic would be as follows:
Download the text html
Remove the formatting and get raw text
Break the text into pages
Save each page (or a few pages together) in a "Page" object
Display the first "Page" object
Listener for scrolling to the end of the page
Display the next "Page" object
Repeat Steps 6, 7

Updating a ViewPager without interrupting the child displayed

I'm building an Android magazine-reader for our campus publication that pulls articles from a web service and displays them in a ViewPager.
To minimize the initial loading time, I want it to pull a relatively small number of articles (say 10) to begin with. Once it has pulled and displayed those articles, I want it to immediately begin downloading/deserializing the next 10 articles while the user is looking through the first set. Likewise, when they reach the 11th article I want it to go ahead and download the next 10, so that the user can continually browse without ever having to wait for more articles to load. This seems easy enough to accomplish using AsyncTasks, but I've hit one small hitch: When the next set of articles is downloaded and added to the ViewPager, it jumps back to displaying the first page.
How can I add views to the end of the ViewPager's dataset without changing the article being displayed to the user?
you will want to use the Endless Adapter created commonsware.
Or you can open the page again after refreshing the content of the ViewPager. Get the article id of the article user is reading. Open the same article after the ViewPager is refreshed.

Keep the images downloaded in the listview during scrolling

I'm developing my first app and have been reading a LOT here.
I've been trying to find a solution for the following issue for over a week with no luck.
I have an Adapter that extends ArrayAdapter to show image and 3 lines of text in each row.
Inside the getView I assign relevant information for the TextViews and use ImageLoader class to download image and assign it to the ImageView.
Everything works great! I have 4.5 rows visible on my screen (out of total of 20). When I scroll down for the first time the images continue to download and be assigned in right order to the list.
BUT when I scroll back the list looses all the images and start redrawing them again (0.5-1 sec per image) in correct order. From what I've been reading it's the standard list performance but I want to change it.
I want that, once the image was downloaded, it will be "sticked" to the list for the whole session of the current window. Just like in Contacts list or in the Market. It is only 20 images (6-9kb each).
Hope I managed to explain myself.
you need to cache each image after download it, and each time the adapter need it check if its already downloaded get it from cache (disk or memory) otherwise download it.
at first i recommended you to read this tutorial from android dev site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
or use an external lib like this one https://github.com/koush/UrlImageViewHelper
The problem here is that the ArrayAdapter is reusing the list view rows as you scroll, so as you scroll down, the top row will be reused and inserted at the bottom of the list (for performance reasons).
Your best bet here is to try to cache the images locally on your device to avoid calling the ImageLoader every time.
One pretty good library that solves this problem is ignition. It's open source and available here: https://github.com/kaeppler/ignition
Take a look at RemoteImageView for a good example of the caching mechanism.

Android ListView with an incrementally built ListAdapter

I am trying to figure out the right architecture for a list view that loads information from an http endpoint. My problem is that the information to be displayed has both text and image content. If I only load the text content the the UI is very responsive but if I also load the image content then it takes a few seconds for the list to be populated. I parse the content as it comes in and build up a list adapter but what I want to do is build up the list adapter incrementally so that the user sees the information as it becomes available instead of waiting until the last item is processed before any information is displayed. Currently I do everything with the help of AsyncTask so I'm aware of threads and how they can be helpful so I'd like to know how other people have worked around the issue of displaying list based information as quickly as possible.
So this solution doesn't incrementally build the ListView but if the text information comes quickly as you mentioned I think it might help:
Lazy load of images in ListView
Basically this solution will place a stub image in the ImageView until the desired image is finished downloading.
It is not only about loading images as far as i understand your question. Please look at "Implementing a Dynamically Loading Adapter (Endless List)" tutorial: http://codinglines.frankiv.me/post/14552677846/android-implementing-a-dynamically-loading-adapter

Categories

Resources