Android Question Hide BCToast that not hide automatically

asales

Expert
Licensed User
Longtime User
Due this change in the new versions of the Android, I need to change the custom toast message.

I created the code below - based in ShowCustomToast with BCToast - that I can call of any activity (I have several apps made only for Android, with several activities and, at the moment, is not a option to migrate to B4XPages, that I use only in new projects), but I get this issue:

- If I show the BCToast in a panel and the user close the panel, before the toast disapears, if I open the panel, the toast still there.

How can I hide/release the toast, if it don't disapears automatically?

Thanks in advance for any tip.

B4X:
Sub ShowCustomToast(act As Activity, txt As Object, LongDuration As Boolean, BackgroundColor As Int, TxtColor As Int)
    Private toast As BCToast
    toast.Initialize(act)
    
    Dim duration As Int
    If LongDuration Then duration = 4000 Else duration = 2000
    toast.DurationMs = duration
    
    toast.DefaultTextColor = TxtColor
    toast.pnl.Color = BackgroundColor
    
    toast.Show($"[TextSize=15][Alignment=Center]${txt}[/Alignment][/TextSize]"$)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If I show the BCToast in a panel and the user close the panel, before the toast disapears, if I open the panel, the toast still there.
(Such issues will never happen with B4XPages)

1. Don't make a new BCToast object each time. Create is once and reuse it.
2. Hide it in Activity_Pause with toast.pnl.Visible = False
 
Upvote 0
Top