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

  • Home
  • SEARCH
  • 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 8323625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:46:23+00:00 2026-06-08T23:46:23+00:00

In Android, I see many apps with loading screens. I know about the ProgressBar,

  • 0

In Android, I see many apps with loading screens. I know about the ProgressBar, implementing the AsyncTask method, but I have never seen anyone knowing how they managed to get the value for the total app size, or if they are loading assets, the total asset size.

By dynamically obtaining an app’s total size, I will be able to add additional content to the app upon release, or after release. I could then be able to calculate the total progress the app had loaded.

So far, I made a workaround, shown below:

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();
    }
}

The only main problem to this activity, is that I have to first add new assets to the list here near the top. The list array size is 58.:

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

Then find out the total asset size from that list I wanted to load assets with, then use the total asset size to mark the 100% on my ProgressBar, and continue to update the ProgressBar as needed.

It’s a slow process, and I was told that this may or may not be ideal if a user is to load the app and notice a lag during initialization. As mentioned that the list array is 58, when my app is loaded, it needs to calculate all of the asset size first, before doing the actual initialization.

I would like to make things quicker, just by setting all variables up without using AsyncTask and ProgressBar, but I liked to have a intro loading screen, just like all other apps in Google Play.

Therefore, how do I obtain an app’s total size?

  • 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-08T23:46:24+00:00Added an answer on June 8, 2026 at 11:46 pm

    Instead of using total file size, and calculating progress based on how many bytes are loaded (which would probably increase your load times), just count the number of files loaded, and calculate progress based on total number of files.

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

Sidebar

Related Questions

I have begun evaluating MonoDroid. (I've built many apps using Android+Eclipse) I created new-from-template
I have a very strange problem with Android animations, I tried many different approaches
I can see many examples of getting location. But in almost all the cases
I have an app which I want to run on as many Android phones
I'd like to use the method profiler to see how many times particular methods
While there are many samples around about using OpenGL ES on Android all of
I've been learning Android for about two weeks now (expert in as2/3). I have
I have a question regarding the term 'context' in Android. I see that the
I know that the question about turning on/off GPS programatically on android has been
I would like to see how many visits my website is getting from Android

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.