Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6983841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:28:20+00:00 2026-05-27T18:28:20+00:00

My method is too slow. The result in 265 files it gives me in

  • 0

My method is too slow. The result in 265 files it gives me in 14 seconds.

Method:

private void assetFilesAmount(String path) {
    AssetManager assetManager = getAssets();
    String assets[] = null;
    try {
        assets = assetManager.list(path);
        if (assets.length == 0) {
            filesAmount++;              
        } else {
            for (int i = 0; i < assets.length; ++i) {
                assetFilesAmount(path + "/" + assets[i]);
            }
        }
    } catch (IOException ex) {
        Log.e("tag", "I/O Exception", ex);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:28:21+00:00Added an answer on May 27, 2026 at 6:28 pm

    I ran into the same problem recently (I wanted to copy some files from the assets directory), and it was in a place in the app where a several second wait was just not going to cut it. AssetManager.list() is just too slow. So I came up with a solution, it is ugly but it is fast.

    At least in my case, since the assets folder is built with the app, I am not changing it often. So the solution I came up with was to include a file in the assets directory that listed all of the files in the assets. For example:

    somedir/somefile.txt
    somedir/anotherdir/anotherfile.txt
    somedir/anotherdir/yetanotherfile.txt
    somedir/anotherdir/somanyfiles.txt
    ...
    

    So it loads this list and then loops through the list rather than having to call AssetManager.list();

    It ain’t pretty or graceful, and probably breaks all sorts of coding practices but in my case it took an operation from taking 30 seconds to 300 milliseconds, so it was worth it in my case.

    If your assets folder is changing a lot, and it would be a pain to manually update the list, you could probably put a script into your build process than would make this directory listing file automatically for you on build.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know too much about encryption, I just want to ask, which method
I'm new to Android and SQLite, too. I'm trying to write a method where
I'm having a problem with Android's MediaPlayer in that it is too slow when
As ConsoleFx seems to be progressing too slow (bummer, it had much potential) and
Possible Duplicate: Android Eclipse Plugin Too Slow I'm an Android programmer and when programming
I have made an event system, however, it is too slow. The issue, is
I'd like to override the Serialize methods of the ASP.NET JavaScriptSerializer class. Nothing too
Method chaining is the practice of object methods returning the object itself in order
Method keySet() . Examples works fine, but I not sure if I'm right.
Method M takes 2 parameters, P1 and P2. P2 is a delegate. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.