DocumentFile.canWrite()、DocumentFile.exists() - 使用本地内置手机存储(而非云)时性能较差(占用太多 CPU 时间)

问题描述 投票:0回答:1

我不太确定,但为什么在使用内置手机外部存储(不是云)时,与

DocumentFile
相比,以下
exist
canWrite
File
功能需要太多 CPU 时间?

每个函数调用需要 ~8-30 毫秒。至少应该是一样的(相同的存储)。

对于

File
,它通常不会高于 10 毫秒,平均值通常小于 10 毫秒。

在三星 S10 (Android 12) 和三星 S22 Ultra (Android 13) 上进行测试,使用 SAF 时性能仍然很差

更新了天啊,还有一个功能更糟糕 -

DocumentFile.findFile()
,虽然文件夹包含0-2个文件,但它基本上需要很长时间,疯狂......

android android-file storage-access-framework android-document-provider
1个回答
0
投票

DocumentFile 比经典 File 类慢大约二十倍。

使用 DocumentsContract 代替。

它的速度与 File 类大致相同。

© www.soinside.com 2019 - 2024. All rights reserved.