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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:49:17+00:00 2026-06-07T14:49:17+00:00

Here’s the core of my ProgressBar class: package nttu.edu.activities; import java.io.ByteArrayOutputStream; import java.io.IOException; import

  • 0

Here’s the core of my ProgressBar class:

package nttu.edu.activities;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Stack;

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.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;

public class NewLoadingActivity extends Activity
{
    private ProgressBar bar;
    private AssetManager assetManager;
    private Load loading;

    private class Load
    {
        public Stack<byte[]> stack;
        public Stack<Bitmap> results;
        public Handler handler;
        public int totalByteSize;
        public int currentByteSize;

        private final String[] list =
        { "art/sprites.png" };

        public Load()
        {
            stack = new Stack<byte[]>();
            results = new Stack<Bitmap>();
            handler = new Handler();
            totalByteSize = 0;
            currentByteSize = 0;
        }

        public void loadBar()
        {
            try
            {
                for (int i = 0; i < list.length; i++)
                {
                    byte[] bytes = readFromStream(list[i]);
                    stack.push((byte[]) bytes);
                    totalByteSize += bytes.length;
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            bar.setMax(totalByteSize);
        }

        public void startHandler()
        {
            handler.post(new Runnable()
            {
                public void run()
                {
                    while (currentByteSize < totalByteSize)
                    {
                        try
                        {
                            Thread.sleep(1000);
                            bar.setProgress(currentByteSize);
                        }
                        catch (InterruptedException e)
                        {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }

        public void startLoad(){
            while (stack.size() > 0){
                byte[] bytes = (byte[]) stack.pop();
                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                if (bitmap != null)
                    currentByteSize += bytes.length;
                results.push((Bitmap) bitmap);
            }
            sort();
            finish();
        }

        //This is the place to load specific assets into a class.
        private void sort(){
            Art.sprites = (Bitmap) results.pop();
        }

        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();
        loading = new Load();
        //bar = new ProgressBar(this);
        bar = (ProgressBar) this.findViewById(R.id.loadingBar);
        loading.loadBar();
        loading.startHandler();
        loading.startLoad();
    }

    public void finish()
    {
        Intent intent = new Intent(this, BaseActivity.class);
        intent.putExtra("Success Flag", Art.sprites != null);
        this.setResult(RESULT_OK, intent);
        super.finish();
    }
}

So far, I can only load bitmaps by adding their paths into the sort() function.

The reason I can only load bitmaps is that I don’t know how to differentiate Bitmap loading, Sound loading, and Resource loading, but I wanted to put all of the things needed to be loaded into 1 large class. I just don’t know how to split them up.

I tried splitting the required files up by directory names, or sorting them into subdirectories of their own, like so:

Snippet of the /assets folder's subdirectories

But then I would find myself stuck on finding a new solution to recursive directory listing and stuff, and still wouldn’t be able to fix it. I’ve been tackling the problem for the past 2 days, but nothing came up good.

Here is my result for that, so to prove that I’ve really been doing my homework:

    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’ve been continuing to do more researching on how to split up different file types in a loading screen, but there aren’t any questions on Stack Overflow regarding how to load different files altogether.

With that, I decided to come up with a simple, rough, and bad answer on doing this, and that is to create all resources in bitmaps, and sacrifice sound files for a game application. And to be honest, I don’t want to do that.

Please help me, such as giving me hints, tips, or whatever you’ve got in your sleeves. What should I do, in order to load all sorts of file types in my progress bar? What do I need to look for?

Thanks in advance.

  • 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-07T14:49:21+00:00Added an answer on June 7, 2026 at 2:49 pm

    Here’s how to create a ProgressBar for arbitary files.

    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 the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
Here's my Manifest: <?xml version=1.0 encoding=utf-8?> <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.mappp.mobile android:versionCode=1 android:versionName=1.0 > <supports-screens android:largeScreens=true
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here is the code I use to bring up the activity: startActivity(new Intent(getApplicationContext(), Giveaway.class));
Here is a simple example of some code that compiles using Java 6, but
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.