Android Question temporarily disable screen orientation

drgottjr

Expert
Licensed User
Longtime User
my app allows user to change screen orientation according to preference. no problem.
user can update (via a download) some files from within app. no problem.
but, if user changes screen orientation during file download, things start to go wrong.

i would like to turn off screen orientation temporarily (ie, ignore it) just before the download starts, and then turn it back on after the download has completed. how can i do this?

i'm guessing i could do the download in the background (i think that's a way around android's restarting the app - i could be wrong on that), but i would prefer some kind of simple enable/disable switch that doesn't provoke a restart.

thanks in advance
-go
 

drgottjr

Expert
Licensed User
Longtime User
you can set the orientation with the phone library, for example set it to protrait before the download and afer finishing back to unspecified...: http://www.b4x.com/android/help/phone.html#phone_setscreenorientation

thanks, but i believe setting the screen orientation will trigger a screen change, which will trigger a restart. which is what i'm trying to avoid. i need to tell android to ignore screen orientation changes temporarily. can i do this in b4a? i see this issue has been raised on stackoverflow where those guys are trying to do the same thing in java. several involve exactly the same situation as mine (user flips the phone in the middle of a download). some suggestions involve calls that don't seem to exist in b4a (that is, without reflection).
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
@eurojam answer is correct. It will not trigger a screen orientation if the screen is already in the same orientation.

However the correct way to handle this case is by downloading the file in a service (starter service can be used).

correct again, sirs! with thanks. and SetScreenOrientation with a -1 will release the hold after the download has finished
 
Upvote 0
Top