vibetribe93 vibetribe93 - 1 year ago 99
Java Question

How to sequentially download data on android

i am using rest services on my server with json response. In my android map i am using retrofit with gson to pull that data and store it in my custom list view. My question is what is the best way download data from my server sequentially, eg. first 10 items from the server and then when i refresh it by pulling the screen after those 10 items it downloads next 10.

Answer Source

It sounds like you're looking for pagination. This has more to do with your server than your client.

A typical way to implement pagination, is to have your server accept offset and limit parameters for a collection resource.

So for example, say you had a collection of items on your server that you could retrieve with

GET myapi/items

You would introduce the offset and limit query parameters to specify which page you wanted out of your collection.

GET myapi/items?offset=50&limit=25

Then you would program your API client accordingly to make use of the values.

You can roll your own paging mechanism on the server, or you can use something that fits with the language and / or framework you're using, which is probably a better way to go about this (best not to re-invent the wheel). For example, I'm using Spring, so use the paging features of spring-data.

This video has a fairly good explanation of paging starting at 53:00

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download