The application is disabled when the warning dialog box is opened, and the phone (emulator) changes orientation

Guys, I searched and studied about this all day. The application crashes not only when the dialog is opened, but also when the counter is opened (and I am sure that it will be many other scenarios that I have not encountered).

choosing between onRetainNonConfigurationInstance () and onConfigurationChanged (Configuration newConfig) will not help me. (maybe I'm wrong) - in fact, I prefer to use the first.

BUT I want to ask: for one open dialog box or open spinner do I need to create everything from scratch? is this the way? sometimes it is useless to reinitialize a large class with a large number of widgets inside just for a while, when the user can change the orientation.

plz give me hints and recommendations. Thank you in advance.

Edited by:

Error code: 01-25 17:56:48.182: ERROR/WindowManager(312): Activity XXX has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e63058 that was originally added here 01-25 17:56:48.182: ERROR/WindowManager(312): android.view.WindowLeaked: Activity XXX has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e63058 that was originally added here 01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.ViewRoot.<init>(ViewRoot.java:247) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.Window$LocalWindowManager.addView(Window.java:424) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.app.Dialog.show(Dialog.java:241) 01-25 17:56:48.182: ERROR/WindowManager(312): at XXX.menuGroupDialog(XXX.java:946) 0 1-25 17:56:48.182: ERROR/WindowManager(312): at XXX.onOptionsItemSelected (GroupManagement.java:257) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.app.Activity.onMenuItemSelected(Activity.java:2195)01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.View$PerformClick.run(View.java:8816) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.os.Handler.handleCallback(Handler.java:587) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.os.Handler.dispatchMessage(Handler.java:92) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.os.Looper.loop(Looper.java:123) 01-25 17:56:48.182: ERROR/WindowManager(312): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-25 17:56:48.182: ERROR/WindowManager(312): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 17:56:48.182: ERROR/WindowManager(312): at java.lang.reflect.Method.invoke(Method.java:521) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-25 17:56:48.182: ERROR/WindowManager(312): at dalvik.system.NativeStart.main(Native Method) 

I know that this is from a call to the reject () function. but how can I handle orientation changes when opening a dialog?

+1
source share
4 answers

Are you using progressDialog.show() and progressbarDialog.dismiss() in AyncTask?

If so, try using showDialog(id) and dismissDialog(id) in AyncTask instead. You will need to write a special dialog in onCreateDialog() to display the download dialog. showDialog and rejectDialog are activity level methods. I mean, they trigger an action or its context. Therefore, even if activity is restored after a change in orientation, the last context will be available for dialogue.

check the sample code here. Change the case of DIALOG_PROGRESS in it according to your requirement.

In addition, onRetainNonConfigurationInstance() works great with orientation changes. This is simply due to a window leak problem, you cannot see it.

+5
source

By default, your activity is destroyed and recreated when the orientation changes. You can disable this feature and manually change this configuration change by setting the configChanges attribute.

+1
source

You can either disable configuration changes, that is, you can stop the application from trying to redraw after changing the orientation of the phone using XML in the manifest file:

 <activity android:name=".Main" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"> 

When the orientation of your phone changes, by default, Android will try to recreate your page.

+1
source

I had a very similar problem, I solve it with a slight change in the attivity attr. From: android: configChanges = "orientation" To: android: configChanges = "keyboardHidden | orientation"

see here: Spinner dropdown and screen orientation problem

0
source

Source: https://habr.com/ru/post/1342830/


All Articles