Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

android - Spinner drop-down list and screen orientation change problem

I have a problem with a spinner drop down list and changing orientations.

In my activity, I display a dialog in which I have two spinners. When the dialog is shown to the user and the user changes the screen orientation, everything is OK-- in my onPause, I just simply dismiss the dialog.

If the user taps on the spinner, a drop-down list is shown to user before changing orientation. But I have encountered an error when the user doesn't select anything from the drop-down list, and just leaves the list expanded before changing orientation.

I have tried many things to solve this problem (i.e. spinner.setSelection(0) in onSaveInstanceState(), etc.). My idea is to close the drop-down list from the code when the user doesn't select item and an orientation change occurs.

The error is about Android.WindowLeaked:

E/WindowManager( 2455): Activity pl.myapp.WebViewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45041e60 that was originally added here
E/WindowManager( 2455): android.view.WindowLeaked: Activity pl.myapp.WebViewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45041e60 that was originally added here
E/WindowManager( 2455):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
E/WindowManager( 2455):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager( 2455):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager( 2455):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager( 2455):     at android.app.Dialog.show(Dialog.java:241)
E/WindowManager( 2455):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
E/WindowManager( 2455):     at android.widget.Spinner.performClick(Spinner.java:257)
E/WindowManager( 2455):     at android.view.View$PerformClick.run(View.java:8816)
E/WindowManager( 2455):     at android.os.Handler.handleCallback(Handler.java:587)
E/WindowManager( 2455):     at android.os.Handler.dispatchMessage(Handler.java:92)
E/WindowManager( 2455):     at android.os.Looper.loop(Looper.java:123)
E/WindowManager( 2455):     at android.app.ActivityThread.main(ActivityThread.java:4627)
E/WindowManager( 2455):     at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager( 2455):     at java.lang.reflect.Method.invoke(Method.java:521)
E/WindowManager( 2455):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/WindowManager( 2455):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/WindowManager( 2455):     at dalvik.system.NativeStart.main(Native Method)

Also, this error appears:

D/AndroidRuntime( 2455): Shutting down VM
W/dalvikvm( 2455): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 2455): FATAL EXCEPTION: main
E/AndroidRuntime( 2455): java.lang.IllegalArgumentException: View not attached to window manager
E/AndroidRuntime( 2455):    at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
E/AndroidRuntime( 2455):    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
E/AndroidRuntime( 2455):    at android.view.Window$LocalWindowManager.removeView(Window.java:432)
E/AndroidRuntime( 2455):    at android.app.Dialog.dismissDialog(Dialog.java:278)
E/AndroidRuntime( 2455):    at android.app.Dialog.access$000(Dialog.java:71)
E/AndroidRuntime( 2455):    at android.app.Dialog$1.run(Dialog.java:111)
E/AndroidRuntime( 2455):    at android.app.Dialog.dismiss(Dialog.java:268)
E/AndroidRuntime( 2455):    at android.widget.Spinner.onDetachedFromWindow(Spinner.java:86)
E/AndroidRuntime( 2455):    at android.view.View.dispatchDetachedFromWindow(View.java:6033)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1158)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455):    at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1630)
E/AndroidRuntime( 2455):    at android.view.ViewRoot.doDie(ViewRoot.java:2671)
E/AndroidRuntime( 2455):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1948)
E/AndroidRuntime( 2455):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2455):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2455):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2455):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2455):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2455):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2455):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2455):    at dalvik.system.NativeStart.main(Native Method)

EDIT

SOLUTION :

Finally I found what cause this *&#$% error. In manifest in my Activity I have android:configChanges="orientation" , when I change it to android:configChanges="keyboardHidden|orientation" problem is gone !

Thx 4 help !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had an idea to prevent orientation changes when dialog with spinner is displayed, but found that there is no reliable way to do that. The best solution that I found is to replace spinner with a button.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...