Android Question B4XLoadingIndicator pause , ProgressDialogShow don't pause

Lucas Siqueira

Active Member
Licensed User
Longtime User
Why when I use B4XLoadingIndicator it gets stuck when I query SQLite, or even I run a For i = 1 To 10000
ProgressDialogShow("Progress") does not crash.

Is there any way to improve the B4XLoadingIndicator code so that it doesn't crash?


Screenrecorder-2022-10-28-17-18-29-813.gif


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private lb_processando As B4XView
    Private li_processando As B4XLoadingIndicator
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")    
    li_processando.Show    
End Sub

Private Sub lb_adicionar_Click
    ProgressDialogShow2("Progress", False)    
    Sleep(100)
    
    For i = 1 To 10000
        lb_processando.Text = $"Progress ${i}"$
    Next
        
    ProgressDialogHide
End Sub
 

Attachments

  • TESTE222.zip
    128.3 KB · Views: 127

Lucas Siqueira

Active Member
Licensed User
Longtime User
Not a bug and not the proper way to post questions.
This is of course not a crash.

Make sure to test performance in release mode.

You should learn how to make async queries and let the main thread (=UI thread) update the ui.
I know there are asynchronous queries, they don't crash the device and everything.

but what I want to understand why ProgressDialogShowdoes not crash, but B4XLoadingIndicator crashes?

is there any way to tell android to continue running B4XLoadingIndicator even doing other tasks?


in this example I used a For i = 1 To 10000 to demonstrate
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
You are keep writing "crash". Does the app crash? Post the error message.
You are keep writing "crash". Does the app crash? Post the error message.
the application does not give an error.
but it looks like it gets all processing for the For i = 1 To 10000 and it doesn't process the B4XLoadingIndicator , but the ProgressDialogShow continues processing.

look at the gif


Screenrecorder-2022-10-28-17-18-29-813.gif


1668088837286.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So why are you keep writing "crashes"? It doesn't crash.
Crash = app quits unexpectedly.

Is there any way to improve the B4XLoadingIndicator code so that it doesn't crash?
No. You need to improve your code and never hold the main thread too long. This is very easy to do. Simply use asynchronous queries: [B4X] SQL with Wait For
And that was my last post in this thread.
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
So why are you keep writing "crashes"? It doesn't crash.
Crash = app quits unexpectedly.


No. You need to improve your code and never hold the main thread too long. This is very easy to do. Simply use asynchronous queries: [B4X] SQL with Wait For
And that was my last post in this thread.

please help me implement for B4XLoadingIndicator not to pause processing when For i = 1 To 10000 is happening



B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private lb_processando As B4XView
    Private li_processando As B4XLoadingIndicator
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")    
    li_processando.Show    
End Sub

Private Sub lb_adicionar_Click
    ProgressDialogShow2("Progress", False)    
    Sleep(100)
    
    For i = 1 To 10000
        lb_processando.Text = $"Progress ${i}"$
    Next
        
    ProgressDialogHide
End Sub
 
Upvote 0

teddybear

Well-Known Member
Licensed User
please help me implement for B4XLoadingIndicator not to pause processing when For i = 1 To 10000 is happening
Just put sleep to for loop, B4XLoadingIndicator will not to pause processing
B4X:
Private Sub lb_adicionar_Click
    ProgressDialogShow2("Progress", False) 
  
    For i = 1 To 10000
        sleep(0)     '<---------Added
        lb_processando.Text = $"Progress ${i}"$
    Next
      
    ProgressDialogHide
End Sub
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Just put sleep to for loop, B4XLoadingIndicator will not to pause processing
B4X:
Private Sub lb_adicionar_Click
    ProgressDialogShow2("Progress", False)
 
    For i = 1 To 10000
        sleep(0)     '<---------Added
        lb_processando.Text = $"Progress ${i}"$
    Next
     
    ProgressDialogHide
End Sub


yes, that makes android wait a bit, and process everything it has to process before going to the next next...
it just happens that it takes a lot longer to execute the for...

is there something to say for android, look, do this process here regardless of what you are doing...

note that the progress doesn't stop even if I don't put a sleep
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Try this
B4X:
Private Sub lb_adicionar_Click
    ProgressDialogShow2("Progress", False)
 
    For i = 1 To 10000
        If i Mod 100 = 0 Then
            Sleep(0)     '<---------Added
            lb_processando.Text = $"Progress ${Round(100 * i / 10000)}%"$
        End If
    Next
      
    ProgressDialogHide
End Sub
 
Upvote 0
Top