First of all. Do you really need to load 2.5 MB of data into memory?
First, a large string is created, then it is parsed (other objects in memory), and then a huge instance of EntMyClass is created. This approach is really ineffective.
I think you have a List in this object. Having only the information you provide, I suggest transferring the data to the database. You can then create an adapter to display data in a ListView.
There are many ways to do this. I use the Jackson library because it is the fastest; GSON should have similar features.
Assuming you have a list in this object below, an example of how to store a json array in a database is given:
//create parser final JsonParser jsonParser = objectMapper.getJsonFactory().createJsonParser(inputStream); JsonToken jsonToken = jsonParser.nextToken(); while ((jsonToken = jsonParser.nextToken()) != null && jsonToken != JsonToken.END_ARRAY) { //map json object to ItemClass final ItemClass item = jsonParser.readValueAs(ItemClass.class); //store in database itemDAO.insert(item); }
And combine it with a database transaction, not only the data will be rolled back in case of an error, but also more efficient.
pawelzieba
source share