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 8224265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:00:28+00:00 2026-06-07T15:00:28+00:00

Here’s my code, albeit very rough coding: public void loadStack(AssetManager manager, String path) {

  • 0

Here’s my code, albeit very rough coding:

public void loadStack(AssetManager manager, String path) {
            String[] list;
            String thePath;
            try {
                list = manager.list(path);
                if (list != null) {
                    for (int i = 0; i < list.length; i++) {
                        try {
                            if (list.length != 0) {
                                if (path.toString() == "") loadStack(manager, list[i]);
                                else {
                                    thePath = path + "/" + list[i];
                                    loadStack(manager, thePath);
                                }
                            }
                            String[] test = manager.list(list[i]);
                            if (test.length != 0) {
                                for (int j = 0; j < test.length; j++) {
                                    byte[] assetBytes = readFromStream(list[i] + "/" + test[j]);
                                    assetStack.push(assetBytes);
                                    totalByteSize += assetBytes.length;
                                    Log.d("Loading", "Stack loads assetBytes of length: " + Integer.toString(assetBytes.length));
                                    // totalStackElementSize = assetStack.size();
                                }
                            }
                            // loadStack(manager, path + "/" + list[i]);
                        }
                        catch (IOException e) {
                            continue;
                        }
                    }
                }
            }
            catch (IOException e1) {
                return;
            }
        }

I’m still trying to improve the code, and all I’m lacking is telling apart what relative paths are subdirectories, and what relative paths are actual paths to files needed to load.

That way, I can rely on using a recursive method to walk through each and every subdirectories of the asset folder, and load only the ones I need.

Can anyone point me to the right direction? Or there’s something I’m missing out on the AssetManager documentation? Thanks in advance. I’m doing the best I can so far.

UPDATE:

Improved my code to this:

public void loadStack(AssetManager manager, String path, int level) {
            try {
                String[] list = manager.list(path);
                if (list != null) {
                    for (int i = 0; i < list.length; i++) {
                        if (level >= 1) loadStack(manager, path + "/" + list[i], level + 1);
                        else if (level == 0) loadStack(manager, list[i], level + 1);
                        else {
                            byte[] byteBuffer = readFromStream(path);
                            assetStack.push(byteBuffer);
                            totalByteSize += byteBuffer.length;
                        }
                    }
                }
            }
            catch (IOException e) {
                Log.e("Loading", "Occurs in AssetLoad.loadStack(AssetManager, String, int), file can't be loaded: " + path);
                throw new RuntimeException("Couldn't load the files correctly.");
            }
        }   

I’m still trying to improve my code. The only problem is that it tends to read folders I haven’t added to the assets folder, or folders I never created before. Those causes logic errors, which I’m avoiding as much as possible.

  • 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-06-07T15:00:30+00:00Added an answer on June 7, 2026 at 3:00 pm

    This is a specific answer to a vague question, however, it works the same way.

    package nttu.edu.activities;
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.LinkedList;
    import java.util.Queue;
    
    import nttu.edu.R;
    import nttu.edu.graphics.Art;
    import android.app.Activity;
    import android.content.Intent;
    import android.content.res.AssetManager;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.os.Handler;
    import android.widget.ProgressBar;
    
    public class NewLoadingActivity extends Activity {
        public ProgressBar bar;
        private AssetManager assetManager;
        public Handler handler;
        public ProgressTask task;
    
        private final String[] list = {
        // Art.sprites
        "art/sprites.png" };
    
        private class ProgressTask extends AsyncTask<Void, Void, Void> {
            public int totalByteSize;
            public int currentByteSize;
            public Queue<Bitmap> bitmapQueue;
            public Queue<byte[]> byteQueue;
    
            public ProgressTask() {
                totalByteSize = 0;
                currentByteSize = 0;
                bitmapQueue = new LinkedList<Bitmap>();
                byteQueue = new LinkedList<byte[]>();
            }
    
            public void onPostExecute(Void params) {
                Art.sprites = bitmapQueue.remove();
                finish();
            }
    
            public void onPreExecute() {
                try {
                    for (int i = 0; i < list.length; i++) {
                        byte[] bytes = readFromStream(list[i]);
                        totalByteSize += bytes.length;
                        byteQueue.add(bytes);
                    }
                    bar.setMax(totalByteSize);
                }
                catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    
            public void onProgressUpdate(Void... params) {
                bar.setProgress(currentByteSize);
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                while (currentByteSize < totalByteSize) {
                    try {
                        Thread.sleep(1000);
                        if (byteQueue.size() > 0) {
                            byte[] bytes = byteQueue.remove();
                            Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                            bitmapQueue.add(bitmap);
                            currentByteSize += bytes.length;
                            this.publishProgress();
                        }
                    }
                    catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }
    
            private byte[] readFromStream(String path) throws IOException {
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                byte[] buffer = new byte[1024];
                int length = 0;
                InputStream input = assetManager.open(path);
                while (input.available() > 0 && (length = input.read(buffer)) != -1)
                    output.write(buffer, 0, length);
                return output.toByteArray();
            }
    
        }
    
        public void onCreate(Bundle b) {
            super.onCreate(b);
            this.setContentView(R.layout.progressbar);
            assetManager = this.getAssets();
            handler = new Handler();
            task = new ProgressTask();
            bar = (ProgressBar) this.findViewById(R.id.loadingBar);
            if (bar == null) throw new RuntimeException("Failed to load the progress bar.");
            task.execute();
        }
    
        public void finish() {
            Intent intent = new Intent(this, MenuActivity.class);
            intent.putExtra("Success Flag", Art.sprites != null);
            this.setResult(RESULT_OK, intent);
            super.finish();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here is an example of what I need http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html I need interactive list to
Here's my code: string strSQL = SELECT * from tMedia where SKU = '
Here is the code: Function getData(ByVal id As String) Dim reader As SqlClient.SqlDataReader Dim
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`

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.