Quirky behavior when rotating screen in API Demos sample, Progress dialog

by blindfold » Thu, 04 Sep 2008 23:53:04 GMT

Sponsored Links
 Yes the dialog should remain visible but be automatically dismissed
after the progress bar fills up, just like when one does not change
the screen orientation. It is the restarting of the application (I
noticed that in my own app) that apparently gets the running progress
dialog handling messed up in ways that are not obvious to circumvent.


Quirky behavior when rotating screen in API Demos sample, Progress dialog

by blindfold » Fri, 05 Sep 2008 00:58:38 GMT

 For my own use I do not care if the progress dialog continues from
where it was or starts all over, so I need no save/restore of its
state. However, the fact that the progress bar does not start at all
after changing screen orientation suggests a bug. The impression I got
is that the progress dialog upon dismiss does not get cleaned up
before the activity restarts and attempts (and fails due to a conflict
with the lingering previous progress dialog) to recreate that same
progress dialog. As an application developer I have no control over
the asynchronous dismiss handling, and I cannot see what happens under
the hood that makes it fail, so the above is just my conjecture.


Sponsored Links

Quirky behavior when rotating screen in API Demos sample, Progress dialog

by blindfold » Fri, 05 Sep 2008 04:31:22 GMT

 Adding one debug output line to AlertDialogSamples.java to get

   Log.i("OIC", "mProgress = " + mProgress);

shows that the handler keeps incrementing mProgress under the
condition that I mentioned, but without dismissing the dialog when
mProgress reaches 100 (and indeed stops counting). I do not see how
adding another trigger message could help with this.

Or more explicitly,

        mProgressHandler = new Handler() {
            public void handleMessage(Message msg) {
                Log.i("OIC", "mProgress = " + mProgress);
                if (mProgress >= MAX_PROGRESS) {
                    Log.i("OIC", "This should dismiss me, but...");
                } else {
                    mProgressHandler.sendEmptyMessageDelayed(0, 100);


09-04 20:11:35.021: INFO/OIC(248): mProgress = 97
09-04 20:11:35.127: INFO/OIC(248): mProgress = 98
09-04 20:11:35.233: INFO/OIC(248): mProgress = 99
09-04 20:11:35.332: INFO/OIC(248): mProgress = 100
09-04 20:11:35.332: INFO/OIC(248): This should dismiss me, but...

the dialog remains on the screen if the screen orientation was changed
during the count.

Or if I add

    protected void onPause() {
       Log.i("OIC", "This too should dismiss me, but...");

then I do get the "This too should dismiss me, but..." upon changing
the screen orientation somewhere during the count (and the count
continues), but the progress dialog still does not go away.


Quirky behavior when rotating screen in API Demos sample, Progress dialog

by blindfold » Fri, 05 Sep 2008 05:45:52 GMT

 Yes we agree now that it is not a trigger message problem.

So what method is there to kill or stop the handler? I could not find

Moreover, killing the old handler will not solve the problem with the
out-of-control new progress dialog that Android instantiates upon a
screen orientation change. I would have to know its handle to dismiss
it, but I cannot know its handle because I did not instantiate the new
progress dialog myself, right?

In other words, is there finally a fix for the problem? How do I
dismiss that new ProgressDialog?



Quirky behavior when rotating screen in API Demos sample, Progress dialog

by blindfold » Sun, 07 Sep 2008 04:16:21 GMT

 I finally obtained a workaround/fix, as described in



Quirky behavior when rotating screen in API Demos sample, Progress dialog

by hackbod » Sun, 07 Sep 2008 14:29:53 GMT


Sure you did.  Please read:
 http://code.google.com/android/reference/android/app/Activity.html #ConfigurationChanges

What happens when an orientation change occurs is that the current
activity is destroyed, and a new one created.  So if you have bugs in
how you handle being destroyed (not correctly closing dialogs,
stopping message pumps) or in how it is re-created from its previously
saved state (not retrieving the state and performing its
initialization based on that), then you will have bugs during an
orientation change.


Other Threads

1. accessing widget in Dialog during unit test

Hi folks

I made a little change to SpinnerActivity from the Android Junit

public void onCreate(Bundle savedInstanceState) {

        dialog = new Dialog(SpinnerActivity.this);

        Spinner spinner = (Spinner)

        this.mAdapter = ArrayAdapter.createFromResource(this,


        OnItemSelectedListener spinnerListener = new




No magic, all I did was create a Dialog (named dialog) and display the
widgets on it.

Then I changed the setUp method in the SpinnerActivityTest code to
look like:

          protected void setUp() throws Exception {


            mActivity = getActivity();

            mSpinner =
              (Spinner) mActivity.findViewById(

All I'm trying to do is get ahold of the Dialog I introduced.  The
problem is, its not working.  mSpinner is coming back as null.

What am I doing wrong?  How do I get ahold of the Dialog?  Failing
that, how do I get ahold of the Spinner that in the Dialog?

This is driving me nuts!



2. Use Gallery to display my app image

In my own app, I have bunches of png files: file1.png, file2.png, file3.png.
I want to use Gallery to display image in my own directory only. When a user
clicks onto the image, it will give back the filename (ex: file1.png).

How do you use Intent to filter only image on my app only and register a
callback to get back path or file name?
Or It's better way to implement a Custom gallery View for my app?


3. application not installed

4. help -> how to connect Android Terminal to PC(ubuntu10.10

5. Consumer closed input channel

6. Consider starring this Android Feature request

7. OutOfMemoryError- while to download big data and storing in db4o