Android Question Check if 'ToastMessageShow' is visible

AndyUK

Member
Licensed User
Hi

I have a problem when my Bluetooth app is initialising in that if a button is pushed it locks up the communication with Bluetooth controller. Is there a way to check when a specific ToastMessageShow is being displayed, then notify when message has cleared?

Andrew
 

AndyUK

Member
Licensed User
I don´t think there is anything about it. You can not read toast-message-content as far as i know.
Is it possible to check if any ToastMessage is being displayed so I can disable all buttons? Even if its only when the initial display appears so I could start a timer.
 

Erel

Administrator
Staff member
Licensed User
B4X:
Sub ShowToastMessage(Msg As String)
 Button1.Enabled = False
 ToastMessageShow(Msg, True)
 Sleep(7000) 'long message duration
 Button1.Enabled = True
End Sub
This code will work if you only show a single toast message. If this is not the case then you need to add:
B4X:
Sub ShowToastMessage(Msg As String)
 ToastIndex = ToastIndex + 1 'global int variable
 Dim MyIndex As Int = ToastIndex
 Button1.Enabled = False
 ToastMessageShow(Msg, True)
 Sleep(7000) 'long message duration
 If ToastIndex <> MyIndex Then Return
 Button1.Enabled = True
End Sub
 

AndyUK

Member
Licensed User
B4X:
Sub ShowToastMessage(Msg As String)
 Button1.Enabled = False
 ToastMessageShow(Msg, True)
 Sleep(7000) 'long message duration
 Button1.Enabled = True
End Sub
This code will work if you only show a single toast message. If this is not the case then you need to add:
B4X:
Sub ShowToastMessage(Msg As String)
 ToastIndex = ToastIndex + 1 'global int variable
 Dim MyIndex As Int = ToastIndex
 Button1.Enabled = False
 ToastMessageShow(Msg, True)
 Sleep(7000) 'long message duration
 If ToastIndex <> MyIndex Then Return
 Button1.Enabled = True
End Sub
Thanks Erel that works fine.

I have also tried to disable a panel which contains 5 buttons which does work except I cannot then enable it again after the delay, any more suggestions please. Also I want to disable a label but all the normal code does not work.

B4X:
Sub ShowToastMessage(Msg As String)
    ToastIndex = ToastIndex + 1 'global int variable
    Dim MyIndex As Int = ToastIndex
    pnl_tank.Initialize(False)
    lbl_hh.Enabled = False
    lbl_mm.Enabled = False
    btn_mode.Enabled = False
'    pnl_tank.Enabled = False
    ToastMessageShow(Msg, True)
    Sleep(6000) 'long message duration
    If ToastIndex <> MyIndex Then Return
    pnl_tank.Initialize(True)
    lbl_hh.Enabled = True
    lbl_mm.Enabled = True
    btn_mode.Enabled = True
'    pnl_tank.Enabled = True
End Sub
 

AndyUK

Member
Licensed User
I thought that when set to 'false' it would disable it, I have now found correct way to stop the panel being displayed so thanks for everybody's help.

Andrew
 

AndyUK

Member
Licensed User
The code I have added for the panel stops it being shown and works. The 2 labels are not working and yes I have tried both, but .enable = false still lets the label to be selected.
 
Top