Question regarding ProgressDialogShow2

IamBot

Member
Licensed User
Longtime User
If I use for example:

B4X:
ProgressDialogShow2("Loading...", False)

the 'Loading' message will appear until it encounters

B4X:
ProgressDialogHide

as it should. But when I activate me keylock while the 'Loading' message is showing, and then quickly resumes the application, the 'Loading' message has disappeared without encountering 'ProgressDialogHide'.

This is quite bad for my application, how can it be fixed?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can do something like:
B4X:
Sub Process_Globals
 Private ProgressBarVisible As Boolean
End Sub

Sub Activity_Resume
 If ProgressBarVisible Then
  ShowProgress
 End If
End Sub

Sub ShowProgress
 ProgressBarVisible = True
 ProgressDialogShow2("Loading...", False)
End Sub

Sub HideProgress
 ProgressDialogHide
 ProgressVisible = False
End Sub
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
You need to add several calls to DoEvents to let it show.
Thank you Erel, I'll try that, but if not, I can come back to this and repost of I have problems.
Got it - DoEvents
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Thank you again Erel,
DoEvents is allowing me the control of the order and it's kind of working.
Working on it though! :)
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
B4X:
Sub mdp3_x_Click
DoEvents
If ShareSettingsOnly.GetSetting("mPlayer") = "active" Then
ShareSettingsOnly.SetSetting("mPlayer", "complete")
mPlayer.Stop
mPlayer.RemoveView
End If
DoEvents
Activity.CloseMenu
ShowProgress
DoEvents
ReleaseOrientation
DoEvents
load_xml("mdp300.xml")
End Sub

This did the trick! I somehow forget about DoEvents, but I won't any longer.
I hope this helps others as forgetful as I am.


The above code did allow a choppy version of update to the spinning circle.
After reading a bit on the Core webpage, I realized that DoEvents should be inserted into the time consuming sub used as a break so that the app can update other waiting processes, like the
spinning circle in the ProgressDialog...

This is what Erel meant...notice the boatload of DoEvents/Breaks. I'll probably trim some out, but for now, it runs pretty smooth for the circle. There is a trade off in lengthening of the process time due to the breaks, so I'll find a happy medium. Thanks again Erel.

B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
DoEvents
    If parser.Parents.IndexOf("item") > -1 Then
    If Name = "sdImg" Then
    DoEvents
        sdImg = Text.ToString
        Else If Name = "title" Then
        DoEvents
            Title = Text.ToString
                Else If Name = "streamUrl" Then
                DoEvents
                streamUrl = Text.ToString  'Link = Text.ToString
                    Else If Name = "synopsis" Then
                    DoEvents
                    synopsis = Text.ToString
                        Else If Name = "genres" Then
                        DoEvents
                        genres = Text.ToString
        End If
  
    End If
    fullDes = "Genre: "&genres&", Description: "&synopsis
    If File.Exists(File.DirAssets, sdImg)= False Then
    sdImg = "androidicon.png"
    End If
    LV1.ScrollingBackgroundColor = Colors.Transparent
    LV1.FastScrollEnabled = True

    If Name = "item" Then
        'File.DirAssets for AssetsDir, ShareSettingsOnly.theDIR for DirExternal/Internal
        Try
        If File.Exists(File.DirAssets, sdImg) Then
        'Log("assets")
        LV1.TwoLinesAndBitmap.ItemHeight = 100dip  
        LV1.TwoLinesAndBitmap.ImageView.Height = 40dip
        LV1.TwoLinesAndBitmap.ImageView.Width = 40dip
        LV1.TwoLinesAndBitmap.Label.Left = LV1.TwoLinesAndBitmap.ImageView.Width + 6dip
        LV1.TwoLinesAndBitmap.Label.Height = 20dip
        LV1.TwoLinesAndBitmap.Label.Gravity = Gravity.NO_GRAVITY
        LV1.TwoLinesAndBitmap.Label.TextSize = 16
        DoEvents
        LV1.TwoLinesAndBitmap.SecondLabel.Top = LV1.TwoLinesAndBitmap.ImageView.Height +2dip
        LV1.TwoLinesAndBitmap.SecondLabel.Left = 0%y
        LV1.TwoLinesAndBitmap.SecondLabel.Height = 50dip
        LV1.TwoLinesAndBitmap.SecondLabel.Gravity = Gravity.NO_GRAVITY
        LV1.TwoLinesAndBitmap.SecondLabel.TextSize = 14
        LV1.AddTwoLinesAndBitmap2(Title, fullDes, LoadBitmap(File.DirAssets, sdImg),streamUrl)
        DoEvents
            Else
            'Log("theDir")
'            LV1.TwoLinesAndBitmap.SecondLabel.Height = 60dip
            LV1.AddTwoLinesAndBitmap2(Title, fullDes, LoadBitmap(ShareSettingsOnly.theDIR, sdImg),streamUrl)
            DoEvents
        End If
        Catch
        'This should only trigger if both fail
        Log("Error in retrieving img file: "&LastException.Message& "Image: " &sdImg)
        End Try
  
    End If

End Sub

Note: This seemed to speed up the program as well. I would think by putting things in order, it stopped a threading competition, so to speak. - Update - This was wrong! Read the comments above...
 
Last edited:
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Hi Erel,

I actually have 4 different xml files. 3 of those files have 100 items, each item then is parsed out to set the 5 values and added to a ListView. These files are selected based on a Menu_Click event one at a time.

Being self taught, It is necessary to comb through the code and check that I am not double initializing, or other duplicate things. (After a lot of hours, I start to see double:confused:)
Android's Activity_Pause and Activity_Resume (I call it "Pause and Effect") that takes place for a variety of reasons, but mainly a device rotation has added a new dimension.
I understand the flow/lifecycle and I am learning what must be coded and where. The StateManager you created, that I changed for my flavor of thinking and coding style has made a huge difference.:D

Erel, your help and that of others here on the forum has been awesome, thank you all!

Let's see..It goes..Copy/Paste/Modify/Done/Oops!/Modify/Done/Repeat...o_O

I am watching your videos, repetitively, then going back and checking my code. It's a worthwhile process.
Thank you for the video's!:D
 
Upvote 0
Top