Saturday, 7 September 2013

Speed Issue Deserializing Arraylist Android

Speed Issue Deserializing Arraylist Android

I have an ArrayList allFeeds and a method to read in serialized data.
@SuppressWarnings("unchecked")
public void loadFile() {
final String FILENAME = "feeds.ser";
File file =
fileContext.getApplicationContext().getFileStreamPath(FILENAME);
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
allFeeds = (ArrayList<Feed>) ois.readObject();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
Although the ArrayList is only small (about 30 objects) it takes a
considerable amount of time to complete. GC_CONCURRENT repeatedly frees up
memory during the execution.
Is there a way of increasing the speed of this operation, or is it simply
just hardware limitations? If so, would it be advisable to push this into
an aSyncTask or background service?

No comments:

Post a Comment