G gordon Member Licensed User Longtime User Sep 6, 2012 #1 I guess I'm missing the obvious but ..... I have a main view which is called in activity_create thus Code: Copy If FirstTime Then Gps1.Initialize("GPS") Activity.LoadLayout("main") createDirectory End If and in that view is a button, the click event of which is this Code: Copy Sub btnMain_Click RemoveViews Activity.LoadLayout("screen2") End Sub (The sub routine RemoveViews is nothing other than a copy of the sub given in the tutorial working with views. ) screen2 has 2 variants, 1 for portrait and 1 for landscape. If screen2 is the active view I had hoped that a screen orientation change would result in screen2 still being in view, but for some reason after such an orientation change the loaded view is "main". Could someone put me out of my misery and explain what i am doing wrong please. Many thanks.
I guess I'm missing the obvious but ..... I have a main view which is called in activity_create thus Code: Copy If FirstTime Then Gps1.Initialize("GPS") Activity.LoadLayout("main") createDirectory End If and in that view is a button, the click event of which is this Code: Copy Sub btnMain_Click RemoveViews Activity.LoadLayout("screen2") End Sub (The sub routine RemoveViews is nothing other than a copy of the sub given in the tutorial working with views. ) screen2 has 2 variants, 1 for portrait and 1 for landscape. If screen2 is the active view I had hoped that a screen orientation change would result in screen2 still being in view, but for some reason after such an orientation change the loaded view is "main". Could someone put me out of my misery and explain what i am doing wrong please. Many thanks.
klaus Expert Licensed User Longtime User Sep 6, 2012 #2 Instead of removing all views and loading a new layout you should use a new activity and then you'll get what you expect. Otherwise it's up to you , in your code, to manage what is the last layout when a screen orientation happens. Best regards. Upvote 0
Instead of removing all views and loading a new layout you should use a new activity and then you'll get what you expect. Otherwise it's up to you , in your code, to manage what is the last layout when a screen orientation happens. Best regards.
G gordon Member Licensed User Longtime User Sep 6, 2012 #3 Ah yes I see now. Thanks for the prompt reply. Upvote 0
mc73 Well-Known Member Licensed User Longtime User Sep 6, 2012 #4 When you have a change in orientation, your activity is 'destroyed'. Then, activity_create is again executed, making the reappearance of your 'main' layout pretty logical. In order to avoid this, you should write somewhere your very last loaded layout and reload this specific one, in your activity_create. This, of course, can lead to a confusion. In case you don't really need for some reasons, multiple layouts in the very same activity, I suggest following Klaus' advice and generate multiple activities. After all, your code will be more crystal, at least this is my opinion. Here's the description of activities' life cycle and so on: http://www.b4x.com/forum/basic4andr...-process-activities-life-cycle.html#post37980 Upvote 0
When you have a change in orientation, your activity is 'destroyed'. Then, activity_create is again executed, making the reappearance of your 'main' layout pretty logical. In order to avoid this, you should write somewhere your very last loaded layout and reload this specific one, in your activity_create. This, of course, can lead to a confusion. In case you don't really need for some reasons, multiple layouts in the very same activity, I suggest following Klaus' advice and generate multiple activities. After all, your code will be more crystal, at least this is my opinion. Here's the description of activities' life cycle and so on: http://www.b4x.com/forum/basic4andr...-process-activities-life-cycle.html#post37980