ProgressBar at start of application

by Pinheiro » Fri, 02 Apr 2010 18:23:51 GMT


Sponsored Links
 Hi!
I'm developing an application where at the start a file is downloaded.
To keep users happy, I want to show an indeterminate progressbar while
the file is being download.
Unfortunately, the progressbar never appears, I only get a black
screen when the file is being downloaded and then the main layout
appears. Here's the code:

        setContentView(R.layout.main);

        ProgressDialog dialog = ProgressDialog.show(
                DownloadFile.this,
                "Wait",
                "Loading");
        dialog.show(); // Stop ProgressBar

        // Download file - could take lots of time
        String str=downloadUrl(" http://somefile.com/file.zip" ;);

       dialog.cancel(); // Stop ProgressBar

 What am I missing? Do I have to create an empty layout with just a
progressbar to do this?

 Thanks in advance for any help :)

Rui Pinheiro

--



ProgressBar at start of application

by ~ TreKing » Fri, 02 Apr 2010 21:13:50 GMT


 




A background thread.

Doing what you're doing is blocking the main (UI) thread, so nothing gets
drawn until your complete all calls you're making in onCreate, including the
long, blocking call to download your file. You want to spawn a thread or
start an AyncTask that will do this work in the background and send messages
to the main (UI) thread to tell it when to show and hide the progress bar.

Read up on threads in general and AsyncTask in particular. This should be a
FAQ at this point.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


ProgressBar at start of application

by Pinheiro » Sat, 03 Apr 2010 00:07:27 GMT


 Ops. Thanks, TreKing!

--



Other Threads

1. MMS message length

Is there an API to support setting MMS upload and download message
size ? Are there predefined sizes that limit how big the outgoing and
incoming messages can be ?
Ajith

--~--~---------~--~----~------------~-------~--~----~

2. DEFAULT_ALL crashes app

I've been using:

Notification.DEFAULT_SOUND

for quite some time with great success.  When I replace that with:

Notification.DEFAULT_ALL

the program crashes when the notification is called.  What's up with
that?
--~--~---------~--~----~------------~-------~--~----~

3. access to class not allowed

4. How to get the body view from an AlertDialog

5. Support for alarms turning phone on

6. Can I use generic/ramdisk.img for my target board?

7. listview focusing issue