Staying on current screen when orientation changed

walterf25

Expert
Licensed User
Longtime User
Hi all, I have a problem and i was wondering if anyone in this forum can help me resolve it, basically i'm working on an app which has 4 different screens, screen1, screen2, etc.... anyhow, when i click on a button on screen one it takes me to the screen specified on the button_click code, but when i change orientation let's say from portrait to landscape the phone takes me back to the first screen, i would like to remain in the current screen regardless of whether the phone orientation changes or not, is there a way to accomplish this, i'm sure is a very simple solution but since i'm relatively speaking new to Basic4Android i need your help. thanks for all your help you fellow have a great day:sign0104:
 

walterf25

Expert
Licensed User
Longtime User
Screen Orientation Change

Thank you very much brother, just what i needed, although i will have to re-write most of my code but i don't think it should take me that long, anyhow again thanks for your support and your help. You're awesome!:wav:
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Screen Orientation Change

Ok, that is the way i'm doing it, i have pnlpage1, pnlpage2, pnlpage3 and pnlpage4. Now, pnlpage1 is the main screen which is called first, this screen has 4 buttons which are assigned to each of the other screens. how can i accomplish staying in the current screen even after the screen orientation changes, i'm sorry if i'm sounding very ignorant but i'm missing something, i already tried using the Statemanager library but it won't work.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
That worked perfect my friend, thank you so much for your help, I really appreciate it, wow that worked amazingly, thanks for your support buddy, God bless you buddy!
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Screen Orientation Change

Hi there, i got another question for you, i got the screen orientation issue taken care of, but now, how can i keep the data displayed on the buttons to stay even when the screen orientation changes, i have 5 buttons and when one of the buttons is pressed it performs a calculation and the 5 different values are assigned to each of the button.text method, when i change orientation even though i stay in the current screen the text on the buttons gets re-setted to the default text. how can i keep the calculation values after changing orientation.

Thanks,:)
 
Upvote 0

legion48

Member
Licensed User
Longtime User
You could use a process global variable that holds the screen number and in Activity_Resume you load the right screen according to the value of the variable or you call the right button_click routine.

Best regards.

I am having the same problem as the original poster and the aswer above fron Klaus fixed it....sort of.

While l can now get the same panel to display when the screen orientation is changed, I have found another problem. If the panel has a webview and was displaying a web page when the orientation changed, then the webview goes blank and does not recover it's url.

I feel I am missing something simple here. It can't be right to be this difficult to preseve screen integrity when changing orientation, surely?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Actually, it sort of is...
When the screen rotates, the app is paused and the resumed...
On resume, I believe (not sure) create is also clled, so the activity return to its "original" state...
The usual advice, In activity Pause, save what ever info is needed, either in variables or in a file, the in Resume, Retrieve those values...
In your particular case, you should reload the webpage on resume...
 
Upvote 0

legion48

Member
Licensed User
Longtime User
Sorry to keep banging on about this subject but I've come to another problem I'm having trouble solving.

I've got the screen orientation sorted and i thought I had the web page reload sorted but apparently not. If the user has navigated away from the original web page, how do reload the current URL in WebView? Is there a simple command that returns the current URL WebView is on?

Tony.
 
Upvote 0

legion48

Member
Licensed User
Longtime User
I found the answer that works for me in a thread by Warwound about his JSInterface library. So simple yet so much time lost searching for it.:BangHead: I'm posting it here in case other newbies are interested.


This saves the current url:

__________________________________________

Sub WebView1_PageFinished (Url As String)

pagerestore=Url

End Sub

_______________________________________________

...and this reloads it when the screen orientation changes;

__________________________________________________
Sub Activity_Resume

WebView1.LoadUrl(pagerestore)

End Sub

___________________________________________________
 
Last edited:
Upvote 0

Widowmaker

New Member
Licensed User
Longtime User
newb here i have the same problem as others i can rotate no problem and the app selects 1 of 4 layout depending on orientation and size eg phone or tablet. this works fine but i have a panel with settings on that dont really belong on a preferences screen. however if the screen is rotated when the panel is visible after the change it is no longer visible.

i have set a boolean if the panel is visible in the activity pause sub, and then check this boolean in resume but it just seems to ignore it.:BangHead:
 
Upvote 0
Top