I'm developing an android app, which will fetch data from my webservice and display it to user. I have a confusion in deciding where to keep pagination(in client side or server side)
My scenario is, I ll take input from the user and make a call to my webservice, to fetch all the data available for the input(response is in Json format) and then, display the data fetched in Recyclerview. I want to display only 50 records initially, then when "show more" button is clicked, the next 50 is displayed.
My data(reponse from webservice) range varies from 0 to 15000 , based on the input from user. And I have other filtering parameters in UI, which will change the rendered data when selected.
So, is it good to fetch all the 15000 records at once and do all kind of processing in client side?
or to fetch 50 records each time when "show more" button is clicked? and to fire new API call whenever filter is changed?
Thanks.
You should never try to fetch such a large number of records in one go, because : 1) your app would have a very slow FRT (First Response Time) 2) the user is unlikely to view more than a couple hundred records at any given time. 3) If the user data (2G/3G/4G) is paid, the user ends up paying for data that he would never see.
So, you should always have pagination on the server side and then your client can request subsequent records as and when needed.
Having said that, network requests would take time and waiting for response every time user clicks on "Show More" would be bad UX as well. So, you need to consider batching requests together and even pre-fetching some data. Here is a nice video for you to see before changing your architecture : https://www.youtube.com/watch?v=3kOx-IPqtqA
Related
I created an android app where I tap on the screen to put some waypoints , get their position and some extra data, then post the data using cakephp. I want to know what are the best practice to send data for my case ?
Example, should I post every point once I tap on the screen or store all the data and post it once for all or post every point into a temporary table then when I click submit I post the data to the real table ?
I really want to know if there are other solution to optimize my application and the loading time ! Thanks.
If the positions are not used by other users until the user completes their interaction I'd save all the positions and send them as a http POST in JSON format as an array [[0,100],[100,331]] or [{"x":0,"y":100},{"x":100,"y":331}] depending on if you're really wanting to optimize it or not use one or the other.
If the positions are used by other users on the site in real time, send every position as they are selected.
I build an android app in which i have a large customer list.It receive data from server in JSON from and I show this JSON in Custom List view. But it take lot of time when Internet show cause of large list of customer.
I want to use Auto Update List when i scroll list it receive next JSON list from server and show it in list view like android mail app.
i am totally new in this so i want help in section from beginning.
You will need to implement pagination on server side. In your original request the server will send you a list of customers (say 20), and total no. of pages (considering each page has 20 customers) or total no. of customers. Based on this data, you can request for the next list of customers once your scroll hits the end, send another request with the page_no or whatever logic you implement to request the next list. Add the next list of customers into your adapter's data.
You can find many code snippets on how to figure out if your scroll has reached the end of list. Here is a guide on how to implement EndLess scroll in your listview.
I have an application that aims to behave like the instagram app. This means:
When the user opens the app, latest content from the local database is displayed, but a request is fired to get the server's latest content. If the server returns such data, the local database gets populated with it and then the UI displays it.
So, how can I handle the gap that this can create between the records that already existed, and the newer ones? Let's say I get 10 items per page from my API, and there are 15 new ones. When the request returns, the latest 10 items get inserted in my local database this leaving a gap of 5 items with the ones that were already there. This could even happen several times if the user doesn't use the app a lot, and the gap could just be huge if they haven't used it in a while, so just firing a lot of request doesn't seem to be the solution.
And the second thing is stale data. Items that have been updated or deleted on the server. I can provide an endpoint to retrieve changes, and soft-delete records so they can still be get but with a "deleted" flag. But the question is: when and how should I request that? It doesn't simply belong in to the "Enter the app -> request latest items" flow. Should I just poll regularly, use some sort of notifications maybe? Then what if the user is offline?
I'm puzzled and I've been googling A LOT lately, and I haven't found a convincing solution. They all are SyncAdapter style stuff.
Thanks.
I'm not sure specific on instagram, but on the app I work on and what I see around other apps, is to delete the feed of local data when you GET the page 0. Then as the user scrolls down, it reloads from internet the next pages.
What I mean by "delete the feed of local data" is, for example:
request is page=0 of friends_recents_photos
onSuccess -> DELETE friends_recents_photos -> INSERT new data
then onScroll -> loadMore
request page=1
onSuccess -> APPEND new data AT end
but that's only the request data of that specific feed, other feeds (e.g. followers), detailed information (e.g. UserData) or cached/downloaded images is kept in cache for fast access.
I have a SearchView in ActionBar and I'm using onQueryTextListener with it. I have a Listview in activity's layout to which the ActionBar belongs. There are two Textviews in ListView. So, as user enter text into searchview, a web query(api) is performed on the text and the results(array) received are used to populate the listview. Just like AutoCompleteTextView but instead displaying results in listview.
I am using a HandlerThread to perform this query and populating the listview and I have implemented it in onQueryTextChange which is working.
But, the problem is that it takes long time to display results. The results are displayed after user is done entering input. However, I want results to be displayed as user enter text(Like Google suggest). How can I do this?
I imagine Google uses cached results on their servers to speed up the response to queries. You could use something like MemCache or Varnish to provide results faster. If the results require searches you could also improve the speed by using a search engine like Apache Solr or Lucene.
Google will also have very good server infrastructure with cached results being located all over the world so always near the user. The results will probably vary from server to server so that they give what local users want. I remember calculating a few years back based on trying to improve response times for online gaming that Europe is something like a tenth of a second from North America.
You can also fake this information. You can download results that you anticipate a user would want on to their device and fill the autocomplete from a database on the device. A request can also be sent to the server at the same time and the autocomplete results updated once the response is received from the server. This to some extent depends on the complexity of what you are searching. If there are only a limited number of results you could easily store them all on the device.
I am developing a news application.
At the main page, I am fetching the news from a server, using JSON.
I am putting the title of this new in the listview alongside a thumbnail image.
The main text of the news (which might be more than 15 lines) does not appear here.
Where I want it to appear is when the user clicks on the title in a specific row in the ListView, the user is taken into a new activity, where a bigger image is shown, alongside the title and the text of the news.
My question is the following. - Which approach is better ?
1 - getting all the data in the first listview, and send them as extras to the second page ? (my concern is that the jsons can get a bit too long sometimes) and show them there ?
2 - just get the title in the first listview, and get another link for the big text (and images) then when the user clicks on the news, open the other activity, and re post/get the data this time with the new link.
Any other suggestions are welcomed.
I would prefer the second option. Because user might not be interested in all the news. Practically, user will read only few news. Say 4 or 5. If you do by second option, you will be fetching only those 4 or 5 data. You fetching all the available data at once will consume large data traffic and time to load the list.
Roughly if you don't want your app to work offline #Karthik Palanivelu is right, and you should only request the extra data if the user wants to read it.
If you do, then that really depends on how many items your list has and how much do you care about the data traffic. If you have 1000 items, 15 lines, let's say 100 characters per line. That's roughly 1,5Mb. Might be a lot if the user is using mobile data, but also might be a little bit if the user is on Wifi. I personally like to give the user the option to always browse the app offline, so in that case I would fetch all the text right away. (Or at least some of the options, maybe the latest 100 or so. But that's my personal opinion)
Bear in mind that's just for the text, you should not fetch all the large images, or it'll consume a lot. Nowadays a lot of people use mobile data, so you should always try to keep the data consumption at a minimum but also give the user a nice experience.