0

读取文件属性并相应地启用/禁用复选框和列表框中的列表值时,我得到了 GUI 闪烁。当我删除此文件读取代码时,GUI 没有闪烁。

在 OnCreate() 中创建首选项之前,我正在阅读属性。附上下面的文件编写代码以供参考。请让我们知道是否有其他方法可以读取和更新首选项状态。

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);
    }
}

-马诺伊

4

1 回答 1

0

为什么要实例化新的 Properties 对象,为属性的每个操作重新读取和重写 props 文件?如果没有这样做的实际原因,只需读取一次并在需要时编写它们(注意 onPause/onResume),并在线程中执行,即:

    最终处理程序处理程序 = 新处理程序();

    [...]

        Runnable writeProps = new Runnable() {
            @覆盖
            公共无效运行(){
                // 在这里做你的工作
                [...]
                // 如果你想通知 UI 线程一些东西,运行这个
                // handler.post(new Runnable() {public void run() { notifyUI(); }});
            }
        };
        线程 thread = new Thread(writeProps, "writeProps");
        线程.start();

    [...]
于 2011-01-17T02:48:05.280 回答