0
\$\begingroup\$

I have some problems with figuring out what value I should put in the function:

int value_needed_to_figure_out = X;
ProgressBar.incrementProgressBy(value_needed_to_figure_out);

I've been researching about loading screens and how to use them. Some examples I've seen have implemented Thread.sleep() in a Handler.post(new Runnable()) function. To me, I got most of that concept of using the Handler to update the ProgressBar, while pretending to do some heavy crunching work. So, I kept looking.

I have read this thread here: How do I load chunks of data from an assest manager during a loading screen?

It said that I can try using a stack it needs to load, and adding a size counter as I add elements to the stack. What does it mean? This is the part where I'm totally stumped.

If anyone would provide some hints, I'll gladly appreciate it. Thanks in advance.

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

The answer in the another thread is pretty straight forward. But a step by step guide:

Make a stack of resources
Fill the stack, as you fill it, count the size of each object and put in the fullSize var
in loop, when still have resources in stack, do:
    pop stack top item
    load this resource
    get the loaded resource size and put it on the currentLoaded var
    update progressbar to currentLoaded / fullSize

As you saw, you get the size of all resources together, this will be the fullSize. And keep another variable together to count what have already been loaded, this will be currentLoaded. Just increase currentLoaded with the last resource loaded size, and get the final percentage with currentLoaded / fullSize.

Was this explanation fine for you?

\$\endgroup\$
7
  • \$\begingroup\$ How do I fill the stack? I tried using AssetManager to obtain the assets, and then got stuck from here. I don't know how you could push individual assets/resource files into the stack one by one. I also tried googling for some examples on filling the stack in android, but nothing good comes up. Link Also, when you push in an asset/resource file into the stack, do you know how to obtain the individual file's size? \$\endgroup\$ Apr 1, 2012 at 6:28
  • \$\begingroup\$ You could do something simple, like a class that store the file name and its size. then just load the file by its name and account its size. That's all \$\endgroup\$ Apr 1, 2012 at 6:30
  • \$\begingroup\$ Nevermind my old comment. I think I can figure the size problem out. The main question is answered, I thank you for your hints. \$\endgroup\$ Apr 1, 2012 at 8:23
  • \$\begingroup\$ @tom_mai78101 Consider also upvoting it, if it was helpful (: \$\endgroup\$ Apr 1, 2012 at 17:35
  • \$\begingroup\$ I need to have 15 reps to upvote. I only have 3. :/ \$\endgroup\$ Apr 1, 2012 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .