Android Question Persist webview through orientation change

Discussion in 'Android Questions' started by barx, Feb 5, 2014.

  1. Baris Karadeniz

    Baris Karadeniz Active Member Licensed User

    I wrote the LoadLayout line to the AfterChange sub as below but everything is mixed at the screen. Should I write something more?

    Code:
    Sub AfterChange
       
    Dim ajo As Panel = Activity
       
    Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth"Null)
       
    Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight"Null)
       
    If width = 0 Or height = 0 Then Return
       ajo.Width = width 
    'update the "activity" width and height
       ajo.Height = height
       WebView1.Width = width
       WebView1.Height = height
       
    Activity.LoadLayout("Layout1")
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    As I previously wrote, I recommend you to avoid using the solution from this thread.
    It breaks the standard program flow. It requires better knowledge of B4A and Android.

    Call Activity.RemoveAllViews before you load the new layout.
     
    lemonisdead likes this.
  3. Baris Karadeniz

    Baris Karadeniz Active Member Licensed User

    Erel, my mind is confused. Because you wrote the statement below at #18;

    You can use this code. However you will need to manually update the layout. Another possible solution is to lock this specific activity orientation.

    And also you wrote the statement below at #20;

    You need to update the layout in AfterChange sub.


    But now you say again avoid using the solution from this thread.

    Can you please explain Can I use the codes in this thread with updating layout manually together or not? And if it is yes, can you please give example codes?
     
  4. lemonisdead

    lemonisdead Well-Known Member Licensed User

    If you disable the ability for the Activity to be destroyed and recreated when the screen is rotated, than you will have to find a way to resize your layout at runtime after having checked that the dimensions changed (that is done with the IME).
    You can lock the Activity's orientation so when the device is rotated, the screen does not change its orientation.

    For example:
    Code:
    #Region Module Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
       
    #SupportedOrientations: portrait
    #End Region
    If you don't lock the Activity's orientation, YES, you will have to manage the dimensions of your Views by code at runtime.

    This is because it will make managing your application more difficult. You then have to well understand the Activity's life process for many reasons : views dimensions, anchors... You won't go through Activity_Create and Activity_Resume

    Of course you can if you want to manage your views and your layout manually, who can ban you from doing it ?

    Make the trial by yourself : add a view to your layout, block the orientation. Detect the screen's dimensions changes using the IME HeightChanged event and try to move and resize your views
     
    mangojack and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice