Better file serialization way for proper cpu usage?
I use following file serialization method to retrieve my data from disk.
public Vector load(String fileName) {
try {
FileInputStream fis = openFileInput(fileName);
ObjectInputStream in = new ObjectInputStream(fis);
Vector obj = (Vector) in.readObject();
in.close();
return obj;
} catch (Exception e) {
Log.e(TAG, e.toString());
}
return null;
}
开发者_如何转开发I have 35K sized file to be serialized. It works perfect but thread uses cpu violently and causes slow application to use. I load this file just once.
Is there any better way for serialization or is there any different way to handle usage cpu of thread ?
You can also consider using Parcel for serialization, it's much more lightweight type of storage.
http://developer.android.com/reference/android/os/Parcelable.html
Don't use Vector, use ArrayList - there won't be any synchronization overhead.
If your operation is going long, just show a ProgressDialog within AsyncTask, like here.
精彩评论