[android-developers] Re: Anyone willing to share...

2008-12-15 Thread Alistair.

I had a sort of similar problem.

This has been discussed here:

http://groups.google.com/group/android-developers/browse_thread/thread/75dc91441a151039/557f1cb99c8f4f8d?lnk=gst&q=java.lang.IllegalArgumentException+screen+orientation+#557f1cb99c8f4f8d



On Dec 15, 4:44 pm, Al Sutton  wrote:
> A code snippet which prevents an "java.lang.IllegalArgumentException:
> View not attached to window manager" being thrown when .dismiss() is
> called on  a progress dialogue box which is on screen when the device
> changes orientation.
>
> Thanks,
>
> Al.
>
> --
> ==
> Funky Android Limited is registered in England & Wales with the
> company number  6741909. The registered head office is Kemp House,
> 152-160 City Road, London,  EC1V 2NX, UK.
>
> The views expressed in this email are those of the author and not
> necessarily those of Funky Android Limited, it's associates, or it's
> subsidiaries.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2008-12-15 Thread Al Sutton

So it looks like the problem still is unsolved.

That thread seems to have a nice theoretical summary from Greg that 
doesn't actually tell you how to fix the problem using the android 
classes available, an link to a post where one person points out that 
the solution given only works for the first orientation change, and a 
few more people asking how to do this...

Is this really a problem with no currently known fully working solution?

Al.

Alistair. wrote:
> I had a sort of similar problem.
>
> This has been discussed here:
>
> http://groups.google.com/group/android-developers/browse_thread/thread/75dc91441a151039/557f1cb99c8f4f8d?lnk=gst&q=java.lang.IllegalArgumentException+screen+orientation+#557f1cb99c8f4f8d
>
>
>
> On Dec 15, 4:44 pm, Al Sutton  wrote:
>   
>> A code snippet which prevents an "java.lang.IllegalArgumentException:
>> View not attached to window manager" being thrown when .dismiss() is
>> called on  a progress dialogue box which is on screen when the device
>> changes orientation.
>>
>> Thanks,
>>
>> Al.
>>
>> --
>> ==
>> Funky Android Limited is registered in England & Wales with the
>> company number  6741909. The registered head office is Kemp House,
>> 152-160 City Road, London,  EC1V 2NX, UK.
>>
>> The views expressed in this email are those of the author and not
>> necessarily those of Funky Android Limited, it's associates, or it's
>> subsidiaries.
>> 
> >
>   


-- 
==
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2008-12-15 Thread Alistair.

Al, just some suggestions but are you managing your progress dialog
from the worker thread?

Perhaps I can help if I describe what I did in my app.

My main activity view has a function 'updateData' which launches the
background thread to fetch the data for the view. Inside the'
updateData' I call 'showDialog' with the id of the busy dialog so:

showDialog(LOADING_DIALOG_KEY);

this is _prior_ to launching the worker thread. When the results are
returned the worker  thread calls a function in the main activity
'showData' which clears the busy dialog with

dismissDialog(LOADING_DIALOG_KEY);

and updates the view. That is, the busy dialog is launched and cleared
from the main activity.

I implemented the onCreateDialog fn:

protected Dialog onCreateDialog(int id)
{
switch (id)
{
case LOADING_DIALOG_KEY:
{
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Updating Forecast...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
default:
break;
}

return super.onCreateDialog(id);
}

The problem I was seeing then was that when I switched the orientation
of the phone when the dialog was active it was never being closed.

I was calling the initial data fetch in the onCreate from my main
activity. When I moved it to the onResume the problem went away. I had
then to ensure that only the first 'onResume' call triggered the
initial data fetch otherwise every time I returned from an activity
launched from the main (like a properties view) it reloaded the data
regardless. I just did this with a flag which was initialised on
creation of the activity.

So, I guess what  I am suggesting is that you move the function which
fetches the data into the main activity, pass a references to the
activity to the worker thread, only deal with the progress dialog by
calling fns from the main activity and implement the onCreateDialog
fn.

Al.






On Dec 15, 5:27 pm, Al Sutton  wrote:
> So it looks like the problem still is unsolved.
>
> That thread seems to have a nice theoretical summary from Greg that
> doesn't actually tell you how to fix the problem using the android
> classes available, an link to a post where one person points out that
> the solution given only works for the first orientation change, and a
> few more people asking how to do this...
>
> Is this really a problem with no currently known fully working solution?
>
> Al.
>
>
>
> Alistair. wrote:
> > I had a sort of similar problem.
>
> > This has been discussed here:
>
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > On Dec 15, 4:44 pm, Al Sutton  wrote:
>
> >> A code snippet which prevents an "java.lang.IllegalArgumentException:
> >> View not attached to window manager" being thrown when .dismiss() is
> >> called on  a progress dialogue box which is on screen when the device
> >> changes orientation.
>
> >> Thanks,
>
> >> Al.
>
> >> --
> >> ==
> >> Funky Android Limited is registered in England & Wales with the
> >> company number  6741909. The registered head office is Kemp House,
> >> 152-160 City Road, London,  EC1V 2NX, UK.
>
> >> The views expressed in this email are those of the author and not
> >> necessarily those of Funky Android Limited, it's associates, or it's
> >> subsidiaries.
>
> --
> ==
> Funky Android Limited is registered in England & Wales with the
> company number  6741909. The registered head office is Kemp House,
> 152-160 City Road, London,  EC1V 2NX, UK.
>
> The views expressed in this email are those of the author and not
> necessarily those of Funky Android Limited, it's associates, or it's
> subsidiaries.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2008-12-16 Thread Al Sutton

I've got two progress dialogues at the moment;

One is created in the onStart method if the app database hasn't been 
populated, the database is populated in a worker thread, and then the 
progress dialogue is dismissed using a Runnable passed to a 
android.os.Handler at the end of the worker threads run method.

The other is created in a WebViewClient and is created in the 
onPageStarted method and dismissed in either of the onLoadReasource, 
onReceivedErro, or onPageFinished methods.

Your scheme seems to the same one that Jay Liang has blogged 
(http://bend-ing.blogspot.com/2008/11/properly-handle-progress-dialog-in.html), 
the only problem is that there is a report that it doesn't work if the 
orientation is switch twice (e.g. someone playing with their phone 
screen and popping it in and out). My other concern with your method is 
how to define LOADING_DIALOG_KEY to ensure there will never be an id 
clash with anything else.

Al.

Alistair. wrote:
> Al, just some suggestions but are you managing your progress dialog
> from the worker thread?
>
> Perhaps I can help if I describe what I did in my app.
>
> My main activity view has a function 'updateData' which launches the
> background thread to fetch the data for the view. Inside the'
> updateData' I call 'showDialog' with the id of the busy dialog so:
>
> showDialog(LOADING_DIALOG_KEY);
>
> this is _prior_ to launching the worker thread. When the results are
> returned the worker  thread calls a function in the main activity
> 'showData' which clears the busy dialog with
>
>   dismissDialog(LOADING_DIALOG_KEY);
>
> and updates the view. That is, the busy dialog is launched and cleared
> from the main activity.
>
> I implemented the onCreateDialog fn:
>
> protected Dialog onCreateDialog(int id)
> {
> switch (id)
> {
>   case LOADING_DIALOG_KEY:
>   {
>   ProgressDialog dialog = new ProgressDialog(this);
>   dialog.setMessage("Updating Forecast...");
>   dialog.setIndeterminate(true);
>   dialog.setCancelable(true);
>   return dialog;
>   }
>   default:
>   break;
> }
>
> return super.onCreateDialog(id);
> }
>
> The problem I was seeing then was that when I switched the orientation
> of the phone when the dialog was active it was never being closed.
>
> I was calling the initial data fetch in the onCreate from my main
> activity. When I moved it to the onResume the problem went away. I had
> then to ensure that only the first 'onResume' call triggered the
> initial data fetch otherwise every time I returned from an activity
> launched from the main (like a properties view) it reloaded the data
> regardless. I just did this with a flag which was initialised on
> creation of the activity.
>
> So, I guess what  I am suggesting is that you move the function which
> fetches the data into the main activity, pass a references to the
> activity to the worker thread, only deal with the progress dialog by
> calling fns from the main activity and implement the onCreateDialog
> fn.
>
> Al.
>
>
>
>
>
>
> On Dec 15, 5:27 pm, Al Sutton  wrote:
>   
>> So it looks like the problem still is unsolved.
>>
>> That thread seems to have a nice theoretical summary from Greg that
>> doesn't actually tell you how to fix the problem using the android
>> classes available, an link to a post where one person points out that
>> the solution given only works for the first orientation change, and a
>> few more people asking how to do this...
>>
>> Is this really a problem with no currently known fully working solution?
>>
>> Al.
>>
>>
>>
>> Alistair. wrote:
>> 
>>> I had a sort of similar problem.
>>>   
>>> This has been discussed here:
>>>   
>>> http://groups.google.com/group/android-developers/browse_thread/threa...
>>>   
>>> On Dec 15, 4:44 pm, Al Sutton  wrote:
>>>   
 A code snippet which prevents an "java.lang.IllegalArgumentException:
 View not attached to window manager" being thrown when .dismiss() is
 called on  a progress dialogue box which is on screen when the device
 changes orientation.
 
 Thanks,
 
 Al.
 
 --
 ==
 Funky Android Limited is registered in England & Wales with the
 company number  6741909. The registered head office is Kemp House,
 152-160 City Road, London,  EC1V 2NX, UK.
 
 The views expressed in this email are those of the author and not
 necessarily those of Funky Android Limited, it's associates, or it's
 subsidiaries.
 
>> --
>> ==
>> Funky Android Limited is registered in England & Wales with the
>> company number  6741909. The registered head office is Kemp House,
>> 152-160 City Road, London,  EC1V 2NX, UK.
>>
>> The views expressed in this email are those of the author and not
>> necessarily those of

[android-developers] Re: Anyone willing to share...

2008-12-16 Thread Dianne Hackborn
You can't call .dismiss() after onDestroy() of an activity.  In the case of
an orientation switch, the previous activity will be destroyed and a new
instance created; after the previous instance is destroyed, its window and
all windows it created are removed from the window manager, and the next
instance will need to take care of re-adding them.

If you are using managed dialogs, most of the work to deal with this should
be done for you, you just need to make sure that you don't do anything with
an old dialog after the onDestroy() call.  The easiest way to do this is
probably to have the main thread handle all of the dialogs, create a Handler
on that thread that is NOT an inner class of the Activity, but just has a
pointer to the current Activity, and clear that pointer in onDestroy() and
set in in onCreate().  Now when another thread wants to dismiss the dialog,
it can send a message requesting this from the handler, and the handler
simply grabs the Activity pointer and if non-null, gets the Dialog pointer
from it and dismisses it if there is one.

On Mon, Dec 15, 2008 at 8:44 AM, Al Sutton  wrote:

>
> A code snippet which prevents an "java.lang.IllegalArgumentException:
> View not attached to window manager" being thrown when .dismiss() is
> called on  a progress dialogue box which is on screen when the device
> changes orientation.
>
> Thanks,
>
> Al.
>
> --
> ==
> Funky Android Limited is registered in England & Wales with the
> company number  6741909. The registered head office is Kemp House,
> 152-160 City Road, London,  EC1V 2NX, UK.
>
> The views expressed in this email are those of the author and not
> necessarily those of Funky Android Limited, it's associates, or it's
> subsidiaries.
>
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2008-12-16 Thread Al Sutton

I beleive the ProgressDialog is a manage dialog because it seems to be 
recreated after the orientation change by the framework.

What your suggesting seems an awful lot of code for a simple task, is 
there really no way to get the ProgressDialog object created after the 
orientation change so that the .dismiss() method can be called on it 
without introducing new threads and object tracking code into the app?

Al.


Dianne Hackborn wrote:
> You can't call .dismiss() after onDestroy() of an activity.  In the 
> case of an orientation switch, the previous activity will be destroyed 
> and a new instance created; after the previous instance is destroyed, 
> its window and all windows it created are removed from the window 
> manager, and the next instance will need to take care of re-adding them.
>
> If you are using managed dialogs, most of the work to deal with this 
> should be done for you, you just need to make sure that you don't do 
> anything with an old dialog after the onDestroy() call.  The easiest 
> way to do this is probably to have the main thread handle all of the 
> dialogs, create a Handler on that thread that is NOT an inner class of 
> the Activity, but just has a pointer to the current Activity, and 
> clear that pointer in onDestroy() and set in in onCreate().  Now when 
> another thread wants to dismiss the dialog, it can send a message 
> requesting this from the handler, and the handler simply grabs the 
> Activity pointer and if non-null, gets the Dialog pointer from it and 
> dismisses it if there is one.
>
> On Mon, Dec 15, 2008 at 8:44 AM, Al Sutton  > wrote:
>
>
> A code snippet which prevents an "java.lang.IllegalArgumentException:
> View not attached to window manager" being thrown when .dismiss() is
> called on  a progress dialogue box which is on screen when the device
> changes orientation.
>
> Thanks,
>
> Al.
>
> --
> ==
> Funky Android Limited is registered in England & Wales with the
> company number  6741909. The registered head office is Kemp House,
> 152-160 City Road, London,  EC1V 2NX, UK.
>
> The views expressed in this email are those of the author and not
> necessarily those of Funky Android Limited, it's associates, or it's
> subsidiaries.
>
>
>
>
>
>
> -- 
> Dianne Hackborn
> Android framework engineer
> hack...@android.com 
>
> 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.
>
>
> >


-- 
==
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2009-01-21 Thread sp

Great, exactly what I was looking for!

However, at first blush, I see a potential race condition if the
thread finishes and sends its message after onDestroy() but before
onCreate() -- then the managed dialog will never be dismissed.  Am I
wrong?

Spiros

On Dec 16 2008, 12:21 pm, "Dianne Hackborn" 
wrote:
> You can't call .dismiss() after onDestroy() of an activity.  In the case of
> an orientation switch, the previous activity will be destroyed and a new
> instance created; after the previous instance is destroyed, its window and
> all windows it created are removed from the window manager, and the next
> instance will need to take care of re-adding them.
>
> If you are using managed dialogs, most of the work to deal with this should
> be done for you, you just need to make sure that you don't do anything with
> an old dialog after the onDestroy() call.  The easiest way to do this is
> probably to have the main thread handle all of the dialogs, create a Handler
> on that thread that is NOT an inner class of the Activity, but just has a
> pointer to the current Activity, and clear that pointer in onDestroy() and
> set in in onCreate().  Now when another thread wants to dismiss the dialog,
> it can send a message requesting this from the handler, and the handler
> simply grabs the Activity pointer and if non-null, gets the Dialog pointer
> from it and dismisses it if there is one.
>
>
>
> On Mon, Dec 15, 2008 at 8:44 AM, Al Sutton  wrote:
>
> > A code snippet which prevents an "java.lang.IllegalArgumentException:
> > View not attached to window manager" being thrown when .dismiss() is
> > called on  a progress dialogue box which is on screen when the device
> > changes orientation.
>
> > Thanks,
>
> > Al.
>
> > --
> > ==
> > Funky Android Limited is registered in England & Wales with the
> > company number  6741909. The registered head office is Kemp House,
> > 152-160 City Road, London,  EC1V 2NX, UK.
>
> > The views expressed in this email are those of the author and not
> > necessarily those of Funky Android Limited, it's associates, or it's
> > subsidiaries.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Anyone willing to share...

2009-01-21 Thread Dianne Hackborn
To be safe, you could set a flag to say it has been dismissed that you check
when creating the next activity.  Generally we call onCreate() immediately
after onDestroy() when switching orientations, but this is a good point that
there may be another message dispatch between them in some cases so to be
correct you need to deal with that.

On Wed, Jan 21, 2009 at 7:24 AM, sp  wrote:

>
> Great, exactly what I was looking for!
>
> However, at first blush, I see a potential race condition if the
> thread finishes and sends its message after onDestroy() but before
> onCreate() -- then the managed dialog will never be dismissed.  Am I
> wrong?
>
> Spiros
>
> On Dec 16 2008, 12:21 pm, "Dianne Hackborn" 
> wrote:
> > You can't call .dismiss() after onDestroy() of an activity.  In the case
> of
> > an orientation switch, the previous activity will be destroyed and a new
> > instance created; after the previous instance is destroyed, its window
> and
> > all windows it created are removed from the window manager, and the next
> > instance will need to take care of re-adding them.
> >
> > If you are using managed dialogs, most of the work to deal with this
> should
> > be done for you, you just need to make sure that you don't do anything
> with
> > an old dialog after the onDestroy() call.  The easiest way to do this is
> > probably to have the main thread handle all of the dialogs, create a
> Handler
> > on that thread that is NOT an inner class of the Activity, but just has a
> > pointer to the current Activity, and clear that pointer in onDestroy()
> and
> > set in in onCreate().  Now when another thread wants to dismiss the
> dialog,
> > it can send a message requesting this from the handler, and the handler
> > simply grabs the Activity pointer and if non-null, gets the Dialog
> pointer
> > from it and dismisses it if there is one.
> >
> >
> >
> > On Mon, Dec 15, 2008 at 8:44 AM, Al Sutton 
> wrote:
> >
> > > A code snippet which prevents an "java.lang.IllegalArgumentException:
> > > View not attached to window manager" being thrown when .dismiss() is
> > > called on  a progress dialogue box which is on screen when the device
> > > changes orientation.
> >
> > > Thanks,
> >
> > > Al.
> >
> > > --
> > > ==
> > > Funky Android Limited is registered in England & Wales with the
> > > company number  6741909. The registered head office is Kemp House,
> > > 152-160 City Road, London,  EC1V 2NX, UK.
> >
> > > The views expressed in this email are those of the author and not
> > > necessarily those of Funky Android Limited, it's associates, or it's
> > > subsidiaries.
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > hack...@android.com
> >
> > 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.
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---