How to deal with orientation change with a ProgressDialog showing?

大兔子大兔子 提交于 2019-11-28 09:04:43

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

You could try disabling orientation changes during the time you show the ProgressDialog.

at the beginning do:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

and enable back after completion:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

Hope this helps.

(If anyone has a proper solution, I would also be interested :-)

Josh

You want to properly handle the activity lifecycle, which means saving and restoring the state of your activity, not attempting to prevent lifecycle changes. Do some reading on AsyncTask vs. the activity lifecycle.

For example: pause-and-resume-asynctasks-android and what-to-do-with-asynctask-in-onpause.

Add this in activity tag in application manifest.xml

<activity android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:name=".your.package"/>

In my case I have used

android:configChanges="orientation" 

but it did not work for me

Following is working fine

<activity android:name=".MyActivity" 
          android:configChanges="orientation|screenSize|screenLayout">
</activity>

You can use the following code in Your Manifest

<activity android:label="@string/app_name" 
        android:configChanges="orientation|keyboardHidden" 
        android:name=".your.package">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!