Android Question [SOLVED] Raise an event when app crashes

manuel_g

Member
Licensed User
Hi

Is there a way to raise an event when the app crashes and do something (like run a service)?

The idea is to send the sqlite db (via ftp in a service) when the app crashes.

Thank you
 

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi

Is there a way to raise an event when the app crashes and do something (like run a service)?

The idea is to send the sqlite db (via ftp in a service) when the app crashes.

Thank you

B4X:
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
        
    
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs.Append("DeviceID " & DeviceID)
    logs.Append(CRLF)
    logs.Append(StackTrace)
    
    SendEmail
    
    Return True
    
End Sub




public Sub SendEmail(ErrorStr As String)
    Try
        
        Dim mail As SMTP
    
        mail.Initialize(Main.MailServer, 587, Main.MailUserName, Main.MailPassword, "SMTP")
    
        mail.StartTLSMode = True

        mail.UseSSL=True
            
        
        mail.To.Add(developerAddress)
        mail.HtmlBody=True
        
            mail.Subject = "Error Log. " & Today & " " & Now
        
        mail.Body =  ErrorStr
        mail.Sender = Main.Email
        mail.AddAttachment(Starter.FileDir, Main.DBFileName)
        mail.HtmlBody=True       
        mail.Send
    
    Catch
        Log("SendEmail " & LastException.Message)
        ShowError("modFun_SendEmail " & LastException.Message)
    End Try
        
End Sub
 
Upvote 0
Top