0

My app pulls data from the web server. The results are given to a ListView.

Question 1: In what format should I transmit data to minimize data usage ?

Question 2: Should I use a SqlLite database to store the results from the server and feed it to the ListView or can I load it a few (say 100) values to the an ArrayList and set it as the data source for the ListView for a better performance ?

user3388324
  • 552
  • 5
  • 17
  • json is cool. sqlite is good, because of the cursor thing, but can be a pain. see http://njzk2.wordpress.com/2013/08/06/json-to-listview/ for a quick tuto on the first question – njzk2 Mar 11 '14 at 14:33

3 Answers3

1

Question 1: In what format should I transmit data to minimize data usage ?

Answer 1: Its depends on your server side data format. If it is in Xml format then you have to
use xml parsing. If its in Json format then you have to use JSON parsing. I suggest to you use JSOn parsing.

Question 2: Should I use a SqlLite database to store the results from the server and feed it to the ListView or can I load it a few (say 100) values to the an ArrayList and set it as the data source for the ListView for a better performance ?

Answer 2 : You can use HashMap arraylist to store your data and retrieve as easily from it. But if you have a bunch of data earlier said by you then you need to use SQLITE database. In which you have to store your all data in it. and after that retrieve from the Database.

Piyush
  • 23,959
  • 6
  • 36
  • 71
0

Data format

The JavaScript Object Notation (JSON) is widely used in transferring data over the net

Storage

That depends on what you're trying to do - if the data is only temporary in nature, what you're suggesting works. If it needs to be stored across application starts, you will need some kind of persistence. A database would be one way to do that.

Remember though, that if you place your data loading code in your activity's onCreate or onResume method (or anywhere in startup callbacks of the activity lifecycle), it will get loaded everytime your activity is created - even if the user just flipped the device. If the data takes long to load (which over the network can always be the case, even if it's just a few bytes), this can result in very bad user experience. One way to deal with this would be using a custom Loader, which can exist separate from your activity and would be able to cache your previously loaded data.

Conceptually, doing this would require you to extend Loader, and override the onStartLoading method to begin loading your data from the network. You should probably also override onStopLoading and onCancelLoad to keep your app from needlessly shoveling data over the connection even if it's not wanted anymore.

Having done this, you would provide LoaderCallbacks (as shown in the link I gave you), and instead of creating a new CursorLoader in the onCreateLoader callback, create an instance of your own custom loader class.

BadIdeaException
  • 1,994
  • 11
  • 26
0

Q1: you can use JSON or Xml for data transferring because these both are standards but JSON is widely used for data driven applications.

Q2: For Large data you can directly load data to list using lazy loading technique, or this is totally dependent on a person, if you store in database to use this data on multiple locations and for data storage, this depends on you

Saad Bilal
  • 1,681
  • 1
  • 15
  • 28
  • Can you explain more on Lazy Loading ? – user3388324 Mar 11 '14 at 14:44
  • The term by itself is self explanatory.. I asked if there are sophisticated schemes to achieve this in android – user3388324 Mar 12 '14 at 08:57
  • have a look: http://andytsui.wordpress.com/2012/05/10/tutorial-lazy-loading-list-views-in-android-binding-44/ http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/ http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/ https://github.com/commonsguy/cwac-endless – Saad Bilal Mar 13 '14 at 07:54