Android Question Orientation in standby causes my module to reload

thughesimsuk

Member
Licensed User
Longtime User
I have written a program in the wonderful B4A! I have a screen that is portrait only that loads records, if I press the power button and go into standby mode I can rotate the screen and change the orientation to landscape then if I unlock the standby mode the module reloads the records again. If I lock the tablet in portrait then unlock it in portrait all is ok. Can someone help? I am using a Galaxy Note 10.1.

This is causing frustration for my users, any help would be most appreciated.

Tom
 

NJDude

Expert
Licensed User
Longtime User
Changing the orientation causes the activity to be recreated, you could lock the app to 1 orientation only or create a flag that will be used to indicate that the data has been already loaded.
 
Upvote 0

thughesimsuk

Member
Licensed User
Longtime User
Thanks NJDude a regular name I see on the forums! The problem with the orientation lock is that my program has sections that are portrait or landscape. Is there a way you can invoke an orientation lock from the application? i.e. If the activity is paused then lock the tablet orientation then unlock it on the resume.

Thanks
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If by sections you mean some activities in portrait and others in landscape, you can actually lock the individual activities to the orientation you need, depends on how your app is designed.
 
Upvote 0

thughesimsuk

Member
Licensed User
Longtime User
I did mean activities, I have put the required orientations in the manifest,

SetActivityAttribute(Audit_1, android:screenOrientation, "landscape")
SetActivityAttribute(Audit_2, android:screenOrientation, "portrait")
SetActivityAttribute(Audit_3, android:screenOrientation, "portrait")

Which works a charm. I just need to somehow temporarily lock the device to a particular orientation when the device is put in standby to stop users destroying the activity by changing the orientation. Does that make sense?
 
Upvote 0

thughesimsuk

Member
Licensed User
Longtime User
** FIXED **
So in my manifest I have the following code,
B4X:
SetActivityAttribute(Audit, android:screenOrientation, "portrait")
SetActivityAttribute(Audit, android:configChanges, "keyboardHidden|orientation|screenSize")
So my "Audit" activity is fixed in portrait and the second line prevents the activity from being destroyed if someone locks the tablet and then changes the orientation.
 
Upvote 0
Top