So, my application stands from two screens.
MainScreen download a list items (list.json) and display the result in a ListView (done).
Then, when the user push on an item, I need to display a details screen, where I write more details about the product (done).
My problem is the following: all item on the main screen have to display an image, but there is no URL for the image at this point. I have only the detailsURL for a second JSON file (this is containing the imageURL itself).
At the moment, when I press on an item I can start download the detailsURL and gain access to the imageURL. My problem with this approach, I'm not able to download the image on the main screen. What is the best practice in this case?
My thoughts so far:
Downloading the detailsURL and fetch the imageURL, when the user scrolling on the list. This is a waste of network communication and memory.
Displaying the images only for the items, where the user already pressed for details page. This is very very beginner approach I would say.
I'm looking forward to see your answer, what is the best practice in this case?
(I don't have the chance to chance the backend structure.)
Related
In my android app, I have a list view and a detail view for selected item. I retrieve the items from my backend server using retrofit.
But is it better to retrieve first the needed information in list view and then to retrieve all the data of selected item in detail view. Or is it better to load all the data of each item directly in the list so that the user does not wait when he selects an item ?
From a UX view, it's not satisfying to force your users to wait throughout your application process, it's better to wait on time for all.
From a performance view, each request call has its overhead (i.e. network load),so going for a large request is faster than many small requests.
It really depends on the type of item you use
To take the extremes :
if you have a list of songs, you don't want to load the entire song data while loading the list. You just want the title, author, eventually the length and when you click on it to show details, you will load the song at that time or it will that a long time to load the list and you will not have enough memory.
On the other hand, if you have simple items (for example books) where you show the title in the list and the only informations you need is the author and editor, you can load everything in one request.
Things to consider :
Your internet speed
the size of the item compared to the size of the data displayed in the list
the size of the list
I am attempting to implement an "infinite" scroll type of feature in my app. The feature will display a list of items. Each item will contain images, text, etc. When the user scrolls down, more items will appear. I would like to know how "cacheing" algorithms works in popular apps and what is the recommended way to implement them.
The problem that I am having is that if the user visibly goes through 100 items, a lot of in-app Memory is used up. This causes the app to crash after seeing many items. I'm convinced that I should store some of these assets onto the File System of the phone and then re-use them once it's seen again. Please correct me if I am wrong.
For example:
Facebook
In the News Feed, as I scroll down, many "news items" contain images/videos/text. If I scroll through 20, everything looks great. As I scroll down quickly to the "bottom" of the news feed after >40 items, it appears to halt for a split second to "load" more items.
Then, when I scroll back up the news feed, it will display the previously viewed items fairly quickly. I guess my question is, are only a limited # of items cached in memory and most items cached on the file system?
How does it work? I assume when the user sees new news feed items , the app must "download" the assets from the Facebook Server. However, if these items become un-visible, and then the user scrolls back to these items, are these items re-downloaded, retrieved from memory cache, or retrieved from file cache?
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
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.
I am building a android aplication which will be consuming a json file from the internet. This json file contains a list of news from a particular website. Each json object contains information such like title, summary, descripition and web links for the news thumbnail and the original image.
I will be displaying in a listview three information: the news thumbnail, the title and the summary. Here resides my problem. I dont want to load all thumbnails from the internet if they wont be displayed. What I am trying to say is that why download a thumbnail from the 30th news if the user wont scroll down the image. So, i will, initially only download the thumnails from those news that are being displayed in the screen and when the user scrolls down to see more news, as soon as the list item appers to the screen i want to download the image and then display.
Is there a way to achieve this? Is it possible to find out if the list item is on the screen? I have been searching all over the internet for a solution for this but i am running out of ideas.
Thanks
T
You essentially want to lazy load your images. This will only load images that are currently being shown and as you scroll through the list view it will go and fetch those currently shown images.