Android Question Plase Help stuck speed function

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi I need to speed this functions I don't know why is so slow. I gathering the data from a job, that download this file really fast, decode and put than on list.

but when I try to fill the listview its slow really slow.

this is a sample from the downloaded data :

B4X:
"title": "Rivalidad ministerial",
"date": "2016-07-10 11:15:34",
"thumb_url": "http:\/\/ibsj.org\/wp-content\/uploads\/2014\/10\/pastor-sugel.png",
"video_url": "https:\/\/www.youtube.com\/watch?v=tg2j20TP5YI",
"audio_url": "http:\/\/ibsj.org\/wp-content\/uploads\/2016\/07\/20160711Rivalidadministerial-SugelMichelen.mp3",
"author": "Sugel Michel\u00e9n"

all the files are in dirasset.


B4X:
For i = 0 To List1.Size -1
Dim pastor As String
If List2.Get(i) = "null" Or List2.Get(i) = 0 Then
Log("lista es vacia")
ListView1.AddTwoLinesAndBitmap( List6.Get(i),List4.Get(i),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
Else
pastor = trim_string2(List2.Get(i))
If File.Exists(File.DirAssets,pastor) = True Then
Log(pastor)
Try
ListView1.AddTwoLinesAndBitmap( List6.Get(i),List4.Get(i),LoadBitmapSample(File.DirAssets,pastor,15dip,15dip))
Catch
Log(LastException)
End Try
Else
ListView1.AddTwoLinesAndBitmap( List6.Get(i),List4.Get(i),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
End If
End If
Next

this is the trim_string2 function

B4X:
Sub trim_string2 (data As String) As String
Dim result As String
If data = "null" Or data.Length = 0 Then
Else
result = data.SubString2(43,data.Length)
Return result
End If
Return ""
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
this is a sample from the downloaded data :
all the files are in dirasset.
? Perhaps you mean the files of your example are in dirassets, because you cannot download and put them there.

Anyway, you can create 2 bitmaps before the loop then replace LoadBitmapSample(File.DirAssets, ...) with the bitmaps.

Also, you can create, again before the loop, a boolean variable to check if file pastor exists (Dim PastorExists As Boolean = FileExist...).

Move Dim pastor As String before the loop.

Remove the Try-Catch block.


You can replace:
B4X:
Sub trim_string2 (data As String) As String
Dim result As String
If data = "null" Or data.Length = 0 Then
Else
result = data.SubString2(43,data.Length)
Return result
End If
Return ""
End Sub

with:
B4X:
Sub trim_string2 (data As String) As String
Dim result As String = ""
If data.Length > 43 Then
    result = data.SubString2(43,data.Length)
End If
Return result
End Sub
 
Last edited:
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
Works very well, but I discover that must of the delay is in the HTTP JOB, but reduce
like two second, I an receiving 1195 records with 5 info inside each record in json format.

thanks !!!!!
 
Upvote 0
Top