开发者

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


  1. Don't use Vector, use ArrayList - there won't be any synchronization overhead.

  2. If your operation is going long, just show a ProgressDialog within AsyncTask, like here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜