I have a Registration screen where user enters all the registration details and when user clicks on the "Register" button i am showing the progress bar(Progress bar begins to spin) and then takes the user to the home screen.If the user rotates the phone when progress bar is spinning, the progress bar gets dismissed.I want the orientation not to change from potrait to landscape and vice versa,when a progress bar is visible(meaning it is spinning).How to stop the orientation change when progress bar is spinning?Any help would be appreciated.
If you want the activity to not restart during screen orientation change, you can use the below AndroidManifest. xml. Please note the activity android:configChanges=”orientation|screenSize” attribute. This attribute makes the activity not restart when change screen orientation.
Add android:screenOrientation="portrait" to the activity you want to disable landscape mode in.
Short guide: Tap the Settings icon to open the Settings app. Scroll down and tap Accessibility. Scroll down to Interaction controls and tap Auto-rotate screen to turn it off.
This is happening because when screen orientation rotates the Activity gets re-started. In this case you can add configChanges
attribute in your tag in the AndroidManifest file to stop the re-creation of the Activity.
<activity android:name=".Activity_name"
android:configChanges="orientation|keyboardHidden">
By, this your orientation can change will the progress bar is working and also it won't stop though the orientation changes.
UPDATE
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
setContentView(R.layout.login_landscape);
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.login);
}
}
As explained here, calling
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
and then
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
really works like charm... on real devices !
Don't think that it's broken when testing on the emulator, the ctrl+F11 shortcut ALWAYS change the screen orientation, without emulating sensors moves.
Some other references :
And here is Activityinfo
***************** Edited ********************************
And I think you are not able to handle progressbar on screen rotation. Am I right?
So you need not to stop the rotation for this solution. You should handle the progress bar. Here are some tutorials, which are useful for this purpose ..
************** Edited 2 *****************
And some time you looses data when orientation changes. So you can try these tutorials
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With