nvThanh / wwwjdic

Automatically exported from code.google.com/p/wwwjdic
0 stars 0 forks source link

Changing screen orientation causes Force Close #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce:

1. Do any operation that invokes a ProgressDialog (e.g. search the dictionary).
2. While the ProgressDialog is still active, flip the orientation
3. Wait for the background task to finish.

This results in the following exception:

java.lang.IllegalArgumentException: View not attached to window manager

I'm running v0.8 on a Nexus One, Android 2.1.

By the way, I've had this problem before in my own apps (see Pokédroid on
the Market).  I found I could solve it by making the ProgressDialog static
and destroying it and recreating it in the onPause() and onResume()
methods, but I wish there was a more elegant way.  If you discover it, let
me know!  Otherwise, static ProgressDialog should work.

Original issue reported on code.google.com by nolan.la...@gmail.com on 18 May 2010 at 7:18

GoogleCodeExporter commented 9 years ago
Thanks for the report.

See r68 for details, but it seems the only 'right' way to do this is save state 
in
the global application object and recreate onResume(). I am saving the progress
dialog message and the handler onPause(), and passing the new Activity to the 
handler
onResume().

Still needs some testing though.

Original comment by nikolay....@gmail.com on 25 May 2010 at 9:35

GoogleCodeExporter commented 9 years ago
I just discovered an even easier solution.  Just modify the activity's 
declaration in
your manifext xml to say:
android:configChanges="orientation|keyboardHidden|keyboard"

This will make it so that the Activity doesn't destroy and recreate itself 
every time
you change the screen orientation or pop out the keyboard.  Instead of 
onPause(),
onResume(), and onCreate() getting called, you get onConfigurationChange() 
called.  I
have no idea why this isn't the default in Android, because this is much 
easier.  I'm
using this for all my activities now (except for activities whose style is
Theme.Dialog, because it seems to prevent the activity from properly resizing 
its
window width).

Original comment by nolan.la...@gmail.com on 25 May 2010 at 3:20

GoogleCodeExporter commented 9 years ago
Yes, I checked that out too. But then the screen doesn't rotate, and to make it 
consistent I'll have to use it for every activity and I'd like to avoid that.

Original comment by nikolay....@gmail.com on 25 May 2010 at 3:45

GoogleCodeExporter commented 9 years ago
Are you sure the screen doesn't rotate?  I'm using it for the newest version of
Pokédroid, and the screen rotates for me when I turn the phone...

Original comment by nolan.la...@gmail.com on 26 May 2010 at 4:02

GoogleCodeExporter commented 9 years ago
Hm, it does rotate. Maybe I overrode onConfigurationChange() without calling 
through
to super. Might use it after all.

Original comment by nikolay....@gmail.com on 26 May 2010 at 4:27

GoogleCodeExporter commented 9 years ago
fixed

Original comment by nikolay....@gmail.com on 28 May 2010 at 2:25