You just fundamentally shouldn't be taking a long time in onCreate() etc.
If you are taking long enough in there to desire a progress dialog, you are
taking too long.

On Sun, Mar 29, 2009 at 8:40 AM, [email protected] <
[email protected]> wrote:

>
> Hi all,
>
> I have a main activity that launches a sub activity when the user
> clicks a button as follows:
>
> private OnClickListener buttonDirectoryListener = new OnClickListener
> () {
>    public void onClick(View v) {
>        Intent intent = new Intent();
>        intent.setClass(Main.this, Sub.class);
>        startActivity(intent);
>    }
> }
>
> Unfortunatly, the onCreate method of the sub activity can take a long
> time (server request, xml parsing, custom layout creation, ...). So I
> want to display an indeterminate ProgressDialog while the sub activity
> is being created and then dismiss it when main activity is no longer
> visible. I found a few threads claiming that a separate thread
> is needed to run the progress dialog. So I updated my code as follows:
>
> ProgressDialog pd;
>
> private OnClickListener buttonDirectoryListener = new OnClickListener
> () {
>    public void onClick(View v) {
>        pd = new ProgressDialog(this);
>        pd.setIndeterminate(true);
>        pd.show();
>        new Thread() {
>            public void run() {
>                Intent intent = new Intent();
>                intent.setClass(Main.this, Sub.class);
>                startActivity(intent);
>            }
>        }.start();
>    }
> }
>
> @Override
> public void onStop() {
>    super.onStop();
>    pd.dismiss();
> }
>
> It seems to work sometime. But most of the time, the ProgressDialog is
> not showing (or disappareing fastly), I only get a black sreen until
> the sub activity is shown. Poor effect. I guess it might lead to an
> ANR dialog in real situation. I guess the main activity receives
> onStop event before the sub activity is shown. I would like to
> indicate loading through the ProgressDialog until the sub activity
> gets ready to be displayed.
>
> I'm convinced other developers are facing such a problem and I'm
> probably doing something wrong. Any help is welcome. Thanks.
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~
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