You need to provide more information because it is not clear what you are doing.
Sure
Thanks in advance for your time
I am developing a book software (includes 20 chapters and about 200 pages per chapter)
In the activity where the text of a chapter of the book is to be displayed, I have a scroll view, first (in the Activity_Create) I will add a white panel to the scroll view to the total number of pages of the chapter:
For i=1 To number_of_pages
Sleep(0)
If check_back Then Exit
Dim p As Panel
p.Initialize("p")
p.Tag=0
p.Color=Colors.White
sv.Panel.AddView( p , 5%x , (85%y+2%y)*i , 90%x , 85%y )
Next
In another sub , for pages that are visible, the contents are taken from the database and added to the panel :
Sub change_visable_Range_on_jump(VisablePage As Int)
Dim Range_down As Int = Max(1,VisablePage-4)
Dim Range_up As Int = Min(tedadsafhe,VisablePage+4)
For i=1 To Range_down-1
If check_back Then Exit
Dim p As Panel=sv.Panel.GetView(i-1)
If p .Tag=1 Then
p.RemoveAllViews
p.Tag=0
End If
Next
For i=Range_down To Range_up
If check_back Then Exit
Dim p As Panel=sv.Panel.GetView(i-1)
If p .Tag=0 Then CallSubDelayed2(Me,"add_page", i)
Next
For i=Range_up+1 To tedadsafhe
If check_back Then Exit
Dim p As Panel=sv.Panel.GetView(i-1)
If p .Tag=1 Then
p.RemoveAllViews
p.Tag=0
End If
Next
End Sub
Sub add_page(page1 As Object)
If check_back=False Then
Dim page As Int = page1
dim p as panel = sv.Panel.GetView(page-1)
c=sql.ExecQuery("select * from tbl where page = "&page &" and chapter = "&chapter)
For j=0 To c.RowCount-1
Sleep(0)
c.Position=j
If c.GetString("value").Contains("text") Then
dim l as label
l.text=c.getString
p.addview( l , ....)
end if
If c.GetString("value").Contains("image") Then
.....add imageView to p....
end if
If c.GetString("value").Contains("math") Then
.....add KatexMathView to p....
end if
.
.
.
next
end sub
All the codes work well and there are only two problems: the first and most important problem is that when running each of the loops, the software temporarily hangs, and if the return button is touched at that time, the activity_KeyPress sub does not come up And is ignored.
The second problem is related to the same short interruption when performing loops, because it causes the scrolling of the scrollView to be done with a tick and a break, and it does not slip smoothly.
Is it possible to run the loops in one service or another place so that they do not interrupt the main function? What is the correct way to run long and engaging loops?
urious, how many seconds does the loop take to run through the 1000 count?
I wrote the number one thousand, for example
Running speed depends on the power of the device, but running a full season on an activity takes about 10 to 20 seconds. Of course, I only add the first few pages, and the rest of the pages will be added if the view is scrolled, in which case it will take about 5 to 10 seconds at first.
Also, can you post the code you have in the Activity_Keypress sub?
Sub activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode=KeyCodes.KEYCODE_BACK Then
check_back=True
Activity.Finish
End If
Return True
End Sub