Need a good debugger for my B4A app.

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I've written an app using GPS, WebSocket, Database, Spatialite, Google Maps, String Functions and other libraries and classes.
My biggest problem is that especially on some Android 6.0 - 6.0.1 devices, my app eventually crashes without any report.
It's very difficult to understand where the crash occurs because I don't have any crash report. I'm suspecting some libraries but I'm sure I have done somewhere in my code some mistakes!
Does anyone want to help me find out what is wrong?

Thank you in advance!
 

vfafou

Well-Known Member
Licensed User
Longtime User
No!
The crash occurs when the device is in a moving car and it isn't so easy to debug!
 

MarcoRome

Expert
Licensed User
Longtime User
You can add this code in Starter, where [email protected] is your email

B4X:
Sub Process_Globals
    Private logs As StringBuilder
    Private logcat As LogCat
    Private const emailAddress As String = "[email protected]"
End Sub

Sub Service_Create
    logs.Initialize
#if RELEASE
    logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
#end if
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
    logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
    If logs.Length > 5000 Then
        logs.Remove(0, logs.Length - 4000)
    End If
End Sub

'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(StackTrace)
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "Program crashed"
    email.Body = logs
    StartActivity(email.GetIntent)
    Return True
End Sub

Sub Service_Destroy

End Sub

So whe crash you have a message
 
Top