What is the best way to keep a List<String[]>
while my application runs? I am having problems with my approach. It most of the time gives me an OutOfMemory Error since the list is too big.
The List<String[]>
is the result of parsing a csv file that I have downloaded online. What I do is parse the csv in an activity then save its result in a static class member like:
String url = "http://xxx/pdf/pms/pms_test.csv";
try {
InputStream input = new URL(url).openStream();
CSVReader reader = new CSVReader(new InputStreamReader(input));
SchedController.sched = reader.readAll();
input.close();
}
...then access ClassName.sched
on different activities.
I am doing this so that the parsed data will be available in every activity... And I don't have to parse again. What can I do to improve it?
I think you can have 2 approaches.
I suggest you to create a database, this is not difficult and let you to manage well your data. You can do easily lazyLoading with cursor, or use a ORM (ORMLite / Greendao)... I think this is the best way and the fastest to load your data.
Hope this will help you.
Just to add to Paresh's comment. I can suggest something similar I used in my app.
For example I need to display list of Items in a store. (Each item will have ID, name and cost).
To achieve this I first make a request to server to get number of items, say itemCount.
Now I set a limit to number of items displayed in a page say 100.
If the itemCount is greater than 100, I display an alert saying only 100 items will be displayed and a next button
can be added to download next set of items.
Or if it is a search you can ask user to go back and refine the search.
If itemCount is less than 100 then you will not have any issues
This way Paging can be implemented to avoid OutOfMemory
issues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With