iOS Question ToastMessage display time variability when used with Msgbox2

mdehrnsb

Member
Licensed User
Longtime User
I have been using the HUD ToastMessageShow() in my application in various places and have found variability in the display timing. I have narrowed the problem down to its use in conjunction with Msgbox2.

I have two scenarios:

  • ToastMessageShow is displayed when a particular button on the interface is clicked. In this case, the ToastMessageShow works as expected.
  • In the second case, Msgbox2 is called upon after particular button click. The raised event from the Msgbox2 click then calls ToastMessageShow to acknowledge the action was completed. When this occurs, the duration of the ToastMessage is very short, maybe 250 ms or so.
Is there a solution to this problem? I am guessing that it may have something to do with closing the Msgbox and starting the ToastMessage in a short amount of time.

Any assistance is welcomed.
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

I have improved the code (maybe others still need it):
B4X:
Sub ShowToastMessage(Text As String, Duration As Int) 'Don't call it in Application_Start sub
    Dim NaObj As NativeObject = App.KeyController
       NaObj = NaObj.GetField("view")
      
    Dim NaObj2 As NativeObject
    NaObj2 = NaObj2.Initialize("MMBProgressHUD").RunMethod("showHUDAddedTo:animated:",Array(NaObj,True))
    NaObj2.SetField("labelText",Text)
    NaObj2.SetField("mode",5)
   
    Dim T As Timer
    T.Initialize("ToastMessage",Duration)
    T.Enabled = True

End Sub

Sub ToastMessage_Tick
    Dim T As Timer = Sender
    T.Enabled = False
   
    Dim NaObj As NativeObject = App.KeyController
       NaObj = NaObj.GetField("view")
   
    Dim NaObj2 As NativeObject
    NaObj2 = NaObj2.Initialize("MMBProgressHUD").RunMethod("hideHUDForView:animated:",Array(NaObj,True))
End Sub

Can you upload an example project?

Jan
 
Upvote 0

mdehrnsb

Member
Licensed User
Longtime User
Jan,

Thanks for the update but the problem still persists. Your original code you shared with me yesterday caused the app to crash whenever ShowToastMessage() executed when Release mode was built (using the Page reference). This version (above) does not crash but the display time is still short and uncontrollable (values of 10000 for duration have no effect). This is a snippet of what I am implementing:

Sub Button1_Click

Msgbox2("SetLevelConfirmation", "Message", "Title", Array("Yes", "No"))
End Sub


Sub SetLevelConfirmation_Click(ButtonText As String)

If ButtonText = "Yes" Then

' Do some other things here...

' Then..
Main.ShowToastMessage(SET_LEVEL_COMPLETE_MSG, 1500)​

End If
End Sub

In the above scenario, the ToastMessage is displayed for only about ~250ms or so, regardless of the setting for the duration.

I hope this helps.

Mark

 
Upvote 0
Top