开发者

In Android GUI flickers when reading the properties file

I am getting the GUI flicker when reading a file properties and accordin开发者_开发百科gly enabling/disabling checkbox and List value in listbox. when i remove this file reading code the GUI doesnt have flicker.

I am reading the properties before creating the Preferences in OnCreate(). Attached the file write code below for reference.Please let us know is there any other way to read and update the preference staus.

private void SetExtendConf(String key, String strValue)
{
    mProperties = new Properties();
    try {
        File file = new File(FILE_EXT);
        if(!file.exists())
            file.createNewFile();
        file.setWritable(true,false);

        FileInputStream fis = new FileInputStream(file);
           mProperties.load(fis);
        fis.close();
        FileOutputStream stream = new FileOutputStream(file);

        Log.d(TAG, "Setting Values " + key  + ":"+ strValue);
        mProperties.setProperty(key, strValue);
        mProperties.store(stream,"ext.conf");
        stream.close();
    } catch (IOException e) {
        Log.d(TAG, "Could not open properties file: " + GPS_FILE_EXT);
    }
}

-Manoj


Why are you instantiating new Properties objects, re-read and re-write the props file for each operation on properties? If theres no actual reason for doing so, just read them once and write them when needed (taking care of onPause/onResume), and do it in a thread, ie:

    final Handler handler = new Handler();

    [...]

        Runnable writeProps = new Runnable() {
            @Override
            public void run() {
                // do your work here
                [...]
                // run this if you want to notify something to the UI thread 
                // handler.post(new Runnable() {public void run() { notifyUI(); }});
            }
        };
        Thread thread =  new Thread(writeProps, "writeProps");
        thread.start();

    [...]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜