App restarting - orientation changed

Milch

New Member
Hm I am trying for a day or so but still didn't figure out. As a "template" i choose "UserInterfaceMenu" app which i find with one of the free PDF book here. Everything looks fine at the beginning but then i tried to install my app to my phone and when i change orientation or slide physical keyboard out my app restart. This is pretty annoying and i want to fix this but don't really know how. I read about if Firsttime etc. but can't get it to work as i want.

Here is the basic code for sub activity_create

B4X:
Activity.LoadLayout("main")                           ' Loads "Main" layout file
   
   pnlPage1.Initialize("")                                 ' Initializes pnlPage1
   pnlPage1.LoadLayout("Page1")                        ' Loads "Page1" layout file
   Activity.AddView(pnlPage1,0,0,100%x,100%y)   ' Adds pnlPage1 to Activity
   pnlPage1.Visible=True                                    ' Sets pnlPage1 to Visible
   
   pnlPage2.Initialize("")                                 ' Initializes pnlPage2
   pnlPage2.LoadLayout("Page2")                        ' Loads "Page2" layout file
   Activity.AddView(pnlPage2,0,0,100%x,100%y)   ' Adds pnlPage1 to Activity
   pnlPage2.Visible=False                                 ' Sets pnlPage1 to Visible
   
   pnlPage3.Initialize("")                                 ' Initializes pnlPage3
   pnlPage3.LoadLayout("Page3")                        ' Loads "Page3" layout file
   Activity.AddView(pnlPage3,0,0,100%x,100%y)   ' Adds pnlPage1 to Activity
   pnlPage3.Visible=False                                 ' Sets pnlPage1 to Visible
   
   Activity.AddMenuItem("Page 1","mnuPage1")      ' Adds menu item mnuPage1
   Activity.AddMenuItem("Page 2","mnuPage2")      ' Adds menu item mnuPage2
   Activity.AddMenuItem("Page 3","mnuPage3")      ' Adds menu item mnuPage3

And a little bit of background info. Page1 is really a main menu page there are some buttons on it. Page1 layout loads fine and i can click on any button and everything works fine. I have one button on page1 which "open" a webview and open a webpage. So far so good but then i change the orientation or slide a keyboard out and my app restart and i get a page1 (main menu) once again. I just want that even if i change the orientation or slide a keyboard out my application stay where it is without restarting. How to do this?

I know that when orientation is changed Sub Activity_Pause is called but then sub activity_create is called again and i guess page1 becomes visible again. I also tried to insert

if FirstTime then
pnlPage1.LoadLayout("Page1")
endif

and other stuff like this but nothing really helps. Any idea?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I think they are confused that all 3 functions get called on rotation (Pause, Create, Resume). The current visible state of each needs stored in the tag of the panels. Loading Layouts are fine and that isn't want needs in FirstRun. What you need in FirstRun is the initial states stored then set the visible state at the end of create or in Resume. Keep track of the visible states when changed so you can set them properly when the screen rotates. Right now at every rotate you are resetting it to pnlPage1.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Post here just part of that code what are you trying to acomplish because this your code is only activity_create.
 
Upvote 0
Top