Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with orientation change with a ProgressDialog showing?

I am showing a ProgressDialog in the onPreExecute method of an AsyncTask object and canceling the ProgressDialog in the onPostExecute method. In the doInBackground method I am making an HTTP request for user registration. I wish to allow screen orientation changes. When I change the orientation while the doInBackground method is still running, i get all sorts of fun errors like 'IllegalArgumentException: View not attached to window manager' and 'RegisterScreen has leaked window...'

How can I properly continue to show the ProgressDialog after an orientation change? Or maybe, how can I disable orientation change after the user requests to submit their registration?

like image 213
james Avatar asked Sep 12 '10 15:09

james


People also ask

How can we cope with screen orientation changes?

If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.

What happens when screen orientation changes in android?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them . Android does this so that your application can reload resources based on the new configuration.

What class ensures the dialog is displayed properly even when the user changes the device orientation?

The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object. Using DialogFragment to manage the dialog ensures that it correctly handles lifecycle events such as when the user presses the Back button or rotates the screen.


1 Answers

Try adding this attribute android:configChanges="orientation" to your Activity element in the AndroidManifest.xml file.

like image 109
Ragunath Jawahar Avatar answered Oct 06 '22 01:10

Ragunath Jawahar