Android Question DirAssets slow access

slugger

Member
Licensed User
Longtime User
Hello,

I have found that the access to DirAssets files is extremely slow compared to, for example, DirDefaultExternal.

I have added 2 files from the FILES tab in the IDE, and I have copied the same two files into the DirDefaultExternal directory.

The following code:

B4X:
    Dim li As List
    Dim now As Long
    now=DateTime.now

 
    li=File.ListFiles(File.DirAssets)
    Log(DateTime.now-now)
    now=DateTime.now
    li=File.ListFiles(File.DirDefaultExternal)
    Log(DateTime.now-now)

gives me 609 milliseconds and 1 millisecond respectively.

I have also found that the list filled with the DirAssets file list does include 4 more objects that are not present in my project.:

B4X:
(ArrayList) [fonts, images, sounds, webkit]

Why is the access to DirAssets so slow compared to DirDefaultExternal?

Are those extra objects responsible for the DirAssets slow access?

Requesting the list of the files from the DirAssets directory at runtime seems to freeze the app for a while and that is not a nice experience for the user.
 

Todd Carlton

Member
Licensed User
Longtime User
It is my understanding that the files in DirAssets are stored in the distribution archive, which is also why they cannot be written to. The extra time is because the file is within a larger compressed file which is more complex to work with.

From beginner's guide 14.10.1:
"File.DirAssets
The assets folder includes the files that were added with the file manager in the IDE.
It's the Files folder in the project folder.
These files are read-only.
You can not create new files in this folder (which is actually located inside the apk file).
If you have a database file in the Dir.Assets folder you need to copy it to another folder before you
can use it."
 
Upvote 0
Top