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

   super.handleMessage(msg);
   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() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                Log.i("OIC", "mProgress = " + mProgress);
                if (mProgress >= MAX_PROGRESS) {
                    Log.i("OIC", "This should dismiss me, but...");
                    mProgressDialog.dismiss();
                } else {
                    mProgress++;
                    mProgressDialog.incrementProgressBy(1);
                    mProgressHandler.sendEmptyMessageDelayed(0, 100);
                }
            }
        };

gives

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

    @Override
    protected void onPause() {
       super.onPause();
       Log.i("OIC", "This too should dismiss me, but...");
       mProgressDialog.dismiss();
    }

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
it.

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?

Thanks




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



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

 http://code.google.com/p/android/issues/detail?id=857 

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



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. About Monkey Scripting option

Hi

I would like to tell every body that it is possible to simulate a
sequence of events on emulator using monkey scripting option "-f" .

It is successful on android 2.0 sdk


Regards,
Pradeep

-- 

2. Java Question about reflection

Nothing specifically related to Android: more a java question while
struggling making the switch from objective c to java:

1. In Java static methods when implemented in derived classes are
hidden, not overridden. If I have a method foo() in class A and B.
Execution of: A b = new B(); b.foo() will execute method foo() in
class A. That causes me a problem because if I use factory methods in
classes, for each subclass I need to reimplement the static factory
method. I was wondering how people solved this with or without
reflection (I am okay paying the performance toll at object creation).

2. I am trying to replicate the easy functionality of the
NSClassFromString method. Basically, if I have a string for a full
qualified class name, what is the best way to invoke a static method
with a known signature for that class.

In objective c:

Class foo()
{
        NSString *r = @"Bar";
        Class c = NSClassFromString(r);
        return c;
}

then you can call method sna() on class Bar with [foo() sna:d]

So far in Java using reflection, I came up with this convoluted code
that doesn't replicate the behavior for the parameters for the
function (I pass back the object reference, not the method back,
therefore I also have to pass the parameter to call the method):

static SuperClassOfBar foo(float d) {
        try {
            String r = "Bar";
            Class c = Class.forName("com.example."+r); // Fully
qualified name for class
            Class partypes[] = new Class[1];
            partypes[0] = Float.TYPE;
            Method m = c.getDeclaredMethod("sna", partypes);
            Object arglist[] = new Object[1];
            arglist[0] = d;
            Object o = m.invoke(null, arglist);
            return SuperClassOfBar.class.cast(o);
        } catch (Exception e) {
            return null;
        }

It works but it's heavy and not pretty. I understand that leaving a
dynamic language like objective c , I have to make some compromises,
but I may miss something about Java for not having found something
more lightweight for such a generic programming functionality. Any
suggestions to simplify this implementation are welcome.

Thanks in advance.


-- 

3. Layout - Is there some way to do wraparound with horizontal linear layout

4. how can i save my overlays?

5. Motodev Studio for Android Dev?

6. Reminder: IRC office hours tomorrow

7. Loading entire Asset folder