Android Question App reload when change orientation on phone

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello everyone !!
why application reload when i change phone orientation ??

B4X:
#SupportedOrientations: unspecified

is there any way to prevent this?
 

OliverA

Expert
Licensed User
Longtime User
Because that is how Android works. It’s Android that is shutting down and then restarting your application.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
That is an issue that even Almight cannot prevent (sorry for the corny joke)
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Maybe this thread helps you to understand what is happening when you change orientation
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
but if i use this code >

B4X:
Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
    'Log("Orientation > "&GetOrientation)
    
    If (GetOrientation = 0) Then

        If (orientation = 0) Then
            ' ignore
        Else if (orientation = 1) Then
            orientation = 0
            Log("Portrait")
            Activity.RemoveAllViews
            LogColor(SessionID.Get(Session),Colors.Blue)
            Activity.LoadLayout(SessionID.Get(Session))
        End If
    Else If (GetOrientation = 1) Then
        
        If (orientation = 0) Then
            orientation = 1
            Log("LandScape")
            Activity.RemoveAllViews
            LogColor(SessionID.Get(Session),Colors.Blue)
            Activity.LoadLayout(SessionID.Get(Session))
        Else if (orientation = 1) Then
            'ignore
        End If
    End If
    
End Sub

can I get the layout to update to landscape or portrait mode without the app restarting?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Without knowing your application completely, I wonder why you delete all views when the orientation changes. The normal behavior in Android is that the image is rebuilt with a rotation. Then why delete the views? Perhaps it is therefore useful when designing the screen to take into account both screen orientations without having to remove the views.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…