This is a known /problem/ with most (if not all) GUI frameworks. You
see, the code that you write generally runs in the so-called UI
Thread. That means that it runs in the same thread that Android uses
to draw things on the screen. Because of this, the screen will not be
updated until your code finishes executing. For example, if in the
onCreate() function of your Activity, you change something in the UI
(for example, you call setText on a TextView), that change will not
appear on the screen until onCreate() has finished executing, and if
you have some processing to do, obviously the UI will not update until
you finish your processing.

Now, many people tend here to trick themselves into calling another
function like this.doTimeConsumingWork() from within onCreate(). This
will still not work, as onCreate() will not finish until after
doTimeConsumingWork() itself has finished.

The way around this is to use android.os.AsyncTask. Do all your UI
stuff in your onCreate() function (like display the ProgressDialog)
and then use an AsyncTask to do the time consuming work. Also note
that you can not update the UI from another thread, so don't try to do
any UI-related tasks in the doInBackground() function. Instead, do
them in onPreExecute(), onProgressUpdate() and / or onPostExecute().

On Sep 22, 12:52 pm, Feras <[email protected]> wrote:
> No, it doesn't. It's essentially same thing I did, but to make sure I
> ran your code with the following test code to make sure:
>
> ProgressDialog pDialog = new ProgressDialog(this);
>         pDialog.setMessage("Your Message");
>         pDialog.show();
>         try{
>         Thread.sleep(4000);
>         }catch(Exception e){}
>         pDialog.dismiss();
>
> What happens is: a dialog is never shown and seems like nothing
> happens for the 4 seconds. If i remove the dismiss(), the program
> waits 4 seconds, and THEN shows the dialog. Makes it appear as if show
> () gets run only after thread sleeps.
>
> Any ideas?
>
> On Sep 22, 2:00 am, Beanie <[email protected]> wrote:
>
> > This should work
>
> > ProgressDialog pDialog = new ProgressDialog(context);
> > pDialog.setMessage("Your Message");
> > pDialog.show();
>
> > And when you want to close the dialog,
> > pDialog.dismiss();
>
> > Dexter.
>
> > On Sep 22, 11:38 am, Feras <[email protected]> wrote:
>
> > > I have 2 questions actually, while we're on the subject :)
>
> > > 1.  I have some code in my program that processes some stuff, and
> > > takes a few seconds. So I thought logically I can place my dialog show
> > > at the beginning before processing begins, and cancel it at the end.
> > > What ACTUALLY seems to be happening is my dialog shows after the
> > > processing is done... Some demo code to show what I mean with a simple
> > > sleep:
>
> > > ProgressDialog p = ProgressDialog.show(v.getContext(), "updating
> > > things" "things are updating");
> > > try{
> > >    Thread.sleep(4000);}catch(Exception e){}
>
> > > p.cancel();
>
> > > You would assume it'd show the dialog, process/sleep for 4 seconds,
> > > then cancel it. but it doesnt.
>
> > > 2. How can I remove the title bar entirely from the dialog? I've seen
> > > some apps that do this, and am wondering if there's a simple way to do
> > > this programatically, since I dont see that option in the docs.
>
> > > thanks :)
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to