Hello, I have a class with a method to display a message for a given time and then disappear again. This works fine in most cases, but if I e.g. start the default mail app after or before displaying such a message it will never be removed.
Here's the code for the Message Class:
And that's what happens in Main:
I am posting the example file for kind reviewing. It displays a Hello-message when started which disappears after two seconds, as expected. If you tap on 'Send mail' another message displays and will not be removed again when returning from the mail app. What can I do to prevent this from happening?
Thanks a lot
Here's the code for the Message Class:
B4X:
Sub Class_Globals
Dim Caller As Activity
Dim pnmsg As Panel
Dim pnmsgBg As ColorDrawable
Dim lbmsg As Label
End Sub
Public Sub Initialize(Callback As Activity)
Caller = Callback
pnmsg.Initialize("pnmsg")
pnmsgBg.Initialize(Colors.ARGB(240, 80, 150, 200), 20)
pnmsg.Background = pnmsgBg
pnmsg.Height = 100dip
lbmsg.Initialize("lbmsg")
lbmsg.Gravity = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
lbmsg.TextSize = 16
lbmsg.TextColor = Colors.White
lbmsg.Color = Colors.Transparent
lbmsg.Visible = True
pnmsg.AddView(lbmsg, 0dip, 0dip, 80%x, pnmsg.Height)
pnmsg.Visible = True
End Sub
Public Sub Say(msg As String, durance As Int)
lbmsg.Text = msg
pnmsg.RemoveView
Caller.AddView(pnmsg, 10%x, 45%y, 80%x, pnmsg.Height)
Sleep(durance)
pnmsg.RemoveView
End Sub
And that's what happens in Main:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim msg As Message
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
msg.Initialize(Activity)
msg.Say("Hello", 2000)
End Sub
Sub Label1_Click
Dim mail As Email
mail.To.Add("")
mail.Subject = ""
mail.Body = ""
StartActivity(mail.GetIntent)
msg.Say("Open Default Mail App", 2000)
End Sub
I am posting the example file for kind reviewing. It displays a Hello-message when started which disappears after two seconds, as expected. If you tap on 'Send mail' another message displays and will not be removed again when returning from the mail app. What can I do to prevent this from happening?
Thanks a lot