Android Question Sweet Alert Error

Nestor Castro Jr

Member
Licensed User
Hello there,

I made a very simple example to explain my problem. In this code, I show one alert every time that user clicks on Activity. It works in the first time, but in the second time, the app freezes and do not show the alert box.

Sample:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

'
' WARNING!!!!
' The order of the following #AdditionalRes-lines
' must be exact like this
#AdditionalRes: ..\res.MaterialIshProgress
#AdditionalRes: ..\res.SweetAlertDialog

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim sweet As SweetAlertDialog
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")
    sweet.Initialize("Alert")
    sweet.AlertType = sweet.TypeWarning
   
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Click
    sweet.showCancelButton(True).showContentText(True).withCancelText("Not yet").withConfirmText("Yo man").withContentText("Bla bla bla bla").withTitleText("DonManfred present").show  
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Alert_onCancel()  
    Log($"Alert_onCancel()"$)
    sweet.AlertType = sweet.TypeError
    'sweet.withContentText("BLA bla BLA bla BLA")
    sweet.dismissWithAnimation
End Sub

Sub Alert_onConfirm()  
    Log($"Alert_onConfirm()"$)
   
    sweet.dismissWithAnimation
End Sub
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
You always have to initialize it anytime you want to call it. So put all the code in the Activity_click

B4X:
Sub Activity_Click
    sweet.Initialize("Alert")
    sweet.AlertType = sweet.TypeWarning
    sweet.showCancelButton(True).showContentText(True).withCancelText("Not yet").withConfirmText("Yo man").withContentText("Bla bla bla bla").withTitleText("DonManfred present").show 
End Sub
 
Upvote 0
Top