Changing screen orientation runs Activity_Create twice -- what am I doing wrong?

Ati

Member
Licensed User
Longtime User
Hi,

I have this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("menu")
   
   Dim w As Int = Activity.width
   Dim h As Int = Activity.height
   
   Log ("Width: " & w & ", Height: " & h)
   
   If (w > h) Then
      Log ("Width > Height")
   End If
   
End Sub

I'm using an emulator, with Android 2.2 in it.

I start with the phone in portrait mode. Changing the orientation to landscape (ctrl+f11) runs the above code ONCE, logging this:

B4X:
** Activity (menu) Pause, UserClosed = false **
** Activity (menu) Create, isFirst = false **
(Menu, 25) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
Width: 480, Height: 295
Width > Height
** Activity (menu) Resume **

I now clear the log window to make sure I don't copy any old logs.

Then I change back to portrait mode (ctrl+f11 again), and the above code runs TWICE:

B4X:
** Activity (menu) Pause, UserClosed = false **
** Activity (menu) Create, isFirst = false **
(Menu, 25) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
Width: 480, Height: 295
Width > Height
** Activity (menu) Resume **
** Activity (menu) Pause, UserClosed = false **
** Activity (menu) Create, isFirst = false **
(Menu, 25) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
Width: 320, Height: 455
** Activity (menu) Resume **

These are all NEW logs, not the previous log!

Changing to landscape runs the code once, back to portrait, and it runs it twice again.

I'm confused. What am I doing wrong? :-o

Thanks,

Ati
 

Ati

Member
Licensed User
Longtime User
Every time you rotate the device you are re-starting the activity, that's how Android works, read more about it HERE

It gets restarted once when changing to landscape, but TWICE when changing to portrait. (Once with the old orientation, and immediately afterwards with the new orientation.)

I don't see why it restarts the activity twice when changing to portrait. I don't think it should do this, I must have missed something. But what? :-o
 
Upvote 0

Ati

Member
Licensed User
Longtime User
Seems like an emulator bug. Try it with a real device.

Hmm, indeed. It behaves as expected on a real device (both a 2.2 phone and a 3.2 tablet). It only runs twice in the emulator.

Thanks for the tip!
 
Upvote 0
Top