【问题标题】:Codename One Storage behavior on Samsung Galaxy S4三星 Galaxy S4 上的代号一存储行为
【发布时间】:2016-07-03 17:57:11
【问题描述】:

在我的应用程序中,一些数据通过时间戳流入设备,因此我将其存储在 Hashtable 结构中。如果用户需要,它也可以保存到存储中以供以后查看或作为 CSV 文件通过电子邮件发送。这适用于 iOS 设备以及运行 4.4 和 6.0 的两种不同(非三星)品牌的 Android 设备。它不适用于运行 5.0.1 的三星 Galaxy S4。

程序工作如下,用户按下停止按钮后,调用如下方法:

public void stopLogging() {
    isLogging = false;
    dataStorage.flushStorageCache();
    dataStorage.writeObject(fileName, dataLogValues);
    dataLogValues.clear();
}

dataLogValues 是哈希表。

当需要访问记录的数据时,会收集可用文件名列表,其中包含用于访问特定日志的按钮。

public String[] getLogList() {
    return dataStorage.listEntries();
}

dataStorage 之前在构造函数中初始化的地方

dataStorage = Storage.getInstance();

当从存储条目的String[]中选择一个日志时,调用如下方法来检索文件:

public Hashtable<Long, Integer> getLog(String logName) {
    dataStorage.clearCache();
    Hashtable<Long, Integer> log = (Hashtable<Long, Integer>) dataStorage
            .readObject(logName);
    return log;
}

在三星设备上,我在遍历条目名称的 String[] 时添加了一个对话框来显示每个日志文件名,但我只得到以下信息:

"rList-(完整的包名).RallyPacControlStub" 其中 RallyPacControl 是应用程序的名称。如果我还显示 String[] 的大小,我会得到我保存的日志数量的预期条目数。这是我处理日志条目的代码,并避免了我不想要的文件。为此创建的日志文件仅由表示创建时间的时间/日期字符串命名。

String[] logList = dataBuffer.getLogList();
    for (int i = 0; i < logList.length; i++) {
        Dialog.show("Log name", logList[i], "OK", null);
        if (!logList[i].equalsIgnoreCase("Cookies")
                && !logList[i].startsWith("CN1")
                && !logList[i].equals("Infopage")
                && !logList[i].startsWith("Chart")
                && !logList[i].startsWith("Log")) {
            String log = logList[i];
            Container buttonContainer = new Container();
            buttonContainer.setUIID("LogButtonContainer");
            buttonContainer.setName("LogListContainer");
            buttonContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
            buttonContainer.add(new ShowLogButton(log, dataBuffer
                    .getLog(logList[i])));
            buttonContainer.add(new ExportLogButton((logList[i])));
            buttonContainer.add(new LogDeleteButton(log, this));
            logsContainer.add(buttonContainer);
        }
    }

【问题讨论】:

  • 在这样的 10 个案例中,有 9 个问题与用户期望 getClass().getName() 返回有效值有关。这似乎与问题无关,因为您没有显示任何访问存储的代码,甚至存储失败的方式也不是很清楚。
  • 我不确定你的意思,我已经展示了所有访问存储的代码。 dataStorage 变量包含对 Storage.getInstance() 的引用。我使用 writeObject 和 readObject 方法来存储和检索。我使用 listEntries 来获取文件名列表。在大多数设备上,执行此操作后 listEntries 返回的 String 数组具有用于将项目放入 Storage 的预期键。在三星设备上,我只得到上面所说的结果。我没有从源代码构建 Android 应用程序的经验,但我想我需要尝试一下才能更好地记录正在发生的事情。
  • 看起来我可以通过在文件名中添加一个已知前缀然后只使用带有该前缀的存储项目来解决这个问题。

标签: codenameone


【解决方案1】:

我一定错过了Hashtable 读取的行。三星设备可能在层次结构中有一个隐藏文件,以指示您可能可以访问的文件系统元数据,因此使用文件前缀通常是个好主意。

这也可能是来自Log.p() API 的文件被写入该位置。请注意,Storage API 不能保证只返回您写入存储的文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 2013-10-30
    • 2013-05-31
    • 2014-02-28
    • 1970-01-01
    相关资源
    最近更新 更多