0

I have seen posts describing DocumentFile.listFiles() takes a long time. In my case, it is fairly fast but operations on the retrieved instances of DocumentFile take a long time.

DocumentFile[] aFiles = dfDir.listFiles(); //Takes 100 ms with a list of 250 files

//The following takes 5,000ms
for (DocumentFile df : aFiles) {
   boolean bFoo = df.isDirectory(); //takes about 10ms
   String sName = df.getName(); //takes about 10ms
}

Could anyone shed some light on this?

Hong
  • 17,643
  • 21
  • 81
  • 142
  • 1
    The Q/A you posted a link to answers this exact question. [DocumentFile is very slow](https://stackoverflow.com/questions/42186820/documentfile-is-very-slow) – Specifically, "`getName()` invokes `ContentResolver#query()` under the hood ... [this] performs hundreds of queries, which is very inefficient" – user513951 Nov 09 '21 at 20:09
  • 1
    Thank you. I overlooked it. I have linked the answer to this question. – Hong Nov 09 '21 at 20:17

1 Answers1

1

getName() invokes ContentResolver#query() under the hood ... [this] performs hundreds of queries, which is very inefficient."

From an answer to the duplicate question you linked to.

user513951
  • 12,445
  • 7
  • 65
  • 82