Android Question Slow loading of images on Webview

Waldemar Lima

Well-Known Member
Licensed User
The page loads normally the first time, but if I try to reload the page, the images take a few minutes to load ...

code below:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private tamanhoBanner As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module
  
    Private WebView1 As WebView
    Private WebViewExtras As WebViewExtras
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
  
    WebViewExtras.Initialize(WebView1)
    DateTime.DateFormat = "dd/MM/yyyy"
    DateTime.TimeFormat = "HH:mm:ss"
'    Dim encryptedData() As Byte = EncryptText(Starter.LoggedMail&";"&DateTime.Date(DateTime.Now)&";"&DateTime.Time(DateTime.Now), "L4c0nC")

    Dim JavascriptInterface1 As DefaultJavascriptInterface
    JavascriptInterface1.Initialize
    WebViewExtras.AddJavascriptInterface(JavascriptInterface1, "PtgJS")

    Dim WebViewClient1 As DefaultWebViewClient
    WebViewClient1.Initialize("WebViewClient1")
    WebViewExtras.SetWebViewClient(WebViewClient1)
    WebViewExtras.ClearCache(True)
    WebView1.ZoomEnabled = False
    WebViewExtras.ZoomEnabled = False
    WebViewExtras.SetScrollBarStyle(Colors.Transparent)
  
    WebViewExtras.LoadUrl("https://mydomain.com/")
  
    WebViewExtras.SetVerticalScrollbarOverlay(False)
  
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
        'phones
        If 100%x > 100%y Then tamanhoBanner = 32dip Else tamanhoBanner = 50dip
    Else
        'tablets
        tamanhoBanner = 90dip
    End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebViewClient1_ReceivedError (ErrorCode As Int, Description As String, FailingUrl As String)
  
    'WebViewExtras.LoadHtml("")
    LogColor("error : "&ErrorCode,Colors.Red)
    LogColor("desc : "&Description,Colors.Red)
    LogColor("failurl : "&FailingUrl,Colors.Red)
  
End Sub

Sub WebViewClient1_ReceivedSslError(SslErrorHandler1 As SslErrorHandler, SslError1 As SslError)
    Select SslError1.GetPrimaryError
        Case SslError1.SSL_DATE_INVALID
            Log("SSL_DATE_INVALID")
        Case SslError1.SSL_EXPIRED
            Log("SSL_EXPIRED")
        Case SslError1.SSL_IDMISMATCH
            Log("SSL_IDMISMATCH")
        Case SslError1.SSL_INVALID
            Log("SSL_INVALID")
        Case SslError1.SSL_MAX_ERROR
            Log("SSL_MAX_ERROR")
        Case SslError1.SSL_NOTYETVALID
            Log("SSL_NOTYETVALID")
        Case SslError1.SSL_UNTRUSTED
            Log("SSL_UNTRUSTED")
            SslErrorHandler1.Proceed
    End Select
End Sub

Sub WebViewClient1_OverrideUrl (Url As String) As Boolean
    Log(Url)
  
    If (Url.Contains("www.facebook.com")) Then
        Log("autenticando fb")
        WebViewExtras.LoadUrl(Url)
    End If

    'Return True
End Sub

Sub WebViewClient1_PageFinished(Url As String)
    ProgressDialogHide
End Sub

Sub BannerAd_AdClosed
End Sub

Sub BannerAd_ReceiveAd
    Log("recebi ads banner")

    'If (WebView1.Height > ((100%y - ACToolBarLight1.Height) - Panel_ads.Height)) Then
    '    Log("É maior porra !")
        'CustomListView1.asView.Height = (100%y - ACToolBarLight1.Height) - Panel_ads.Height
        'Panel_ads.Top = 100%y - Panel_ads.Height
    '    WebView1.height = ((100%y - ACToolBarLight1.Height) - Panel_ads.Height)
    'End If
  
End Sub

Sub BannerAd_FailedToReceiveAd (ErrorCode As String)
    Log("Error : "&ErrorCode)
    'Msgbox("Error : "&ErrorCode,"error")
    WebView1.Height = 100%y
End Sub

Sub BannerAd_adopened
    Log("La conchita de tu madre")
End Sub
 
Last edited:
Top