1

I am developing a Android application for a website. It has large number of users around 100000. I have to fetch these users to an Arraylist for a custom user search. Is that a good practice to store this much amount of data in an Arraylist (particularly in Android). If not I am planning to use a Sqlite database any suggestions?

3
  • How about storing objects in files...? Commented Apr 25, 2012 at 4:20
  • 1
    where are you fetching them from? Commented Apr 25, 2012 at 4:26
  • from website through API will get json data Commented Apr 25, 2012 at 4:39

3 Answers 3

4

You do not want to use a list of any type.

Databases are optimized to store and search through large amounts of data, if you store these usernames in an ArrayList, you would be responsible for ensuring that you efficiently search.

This seems like a poor idea in the first place. Why would you want to have a local copy of all 1lakh+ usernames? This is terrible waste of bandwidth! It would be better if the application could query the database for the usernames it is searching for. You could then store the results only on the client.

ex: SELECT * FROM `user` WHERE `name` LIKE "david" 

Store only the results from the query. Not every user.

Sign up to request clarification or add additional context in comments.

4 Comments

This also i am considering . But for each keyword we have to go to server to fetch curresponding matches. Thats why i prefer local storage.
+1 @TheRealKingK. This is the best option if you have really 100000 users.
Also you should have mechanism that if you type a character it will connect to the server and if you quickly type second character then the first request should be stop and again you have to connect to the server with the second request.
If you stored the data locally, assuming 20 bytes per name, you are looking at a 2mb download minimum. Unless you have a good method of synchronizing the local and remote databases, this will be very expensive for the user to constantly download.
1

Make Data Classes and make it Serializable and use file storage.. Because if your using DataBase getting and putting data is a different task... storing file Object is better for data handling..

2 Comments

I am not familiar with file storage .We have to use xml files for local storage right?
@ileaf .. not really.. there direct api's for storing objects,,.. you just need to pass the objects... googling will give you many tutorials..
1

It seems that it is not a good idea to store the content in an ArrayList. Depending upon the data or your application, you may get a 'OutOfMemory' error. Try persisting the information to a SQLite database or file.

On the other hand, I do not find the necessity to bulk download the 1 lakh user data and store it locally for search on device. You could make your service to do the search and return only the search results. If this is possible, then storing it in ArrayList is not bad. If the size of your arraylist exceeds the amount tolerated by the DVM, you could override onLowMemory callback and empty the list contents. By this way you could prevent your app from being killed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.