Android Question Starter Service malfunction?

hatzisn

Expert
Licensed User
Longtime User
Hi all,

I am facing a problem with an app I am building and uses two services. The two services are the Starter service and an other service. The other service is started at user's will and at some point crashes. I cannot find the crash point with Debug mode because my app uses the Google Play Services which are not present in the emulator and further more the second service responds to the accelerometer's values changing which cannot be tested in the emulator. In order to find out what is wrong I added the following code to the Application_Error sub of the Starter service. Yet I cannot find what is wrong with the second service because it never reaches the Application_Error sub to send me the error logs and the sub the error occured (sSub changes each time the code execution enters a new sub in order to catch the sub that has the error). Instead I get an error message "App was interrupted" (I do not know if I am translating it right because I see it in Greek). What am I doing wrong?

This is my code in the Starter service:

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private logs As StringBuilder
    Private logcat As LogCat
    Private const emailAddress As String = "bogus@yahoo.com"
    Public sSub As String
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub



Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
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 lngWait As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(lngWait))
    logcat.LogCatStop
    logs.Append("Sub:" & sSub).Append(CRLF).Append(CRLF)
    logs.Append(StackTrace).Append(CRLF).Append(CRLF).Append(Error.Message)
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "The app crashed"
    email.Body = logs.ToString
    StartActivity(email.GetIntent)
    Return True
End Sub

Sub Service_Destroy

End Sub
 

hatzisn

Expert
Licensed User
Longtime User
Hi Erel, thanks for the quick reply. I am testing it in a real device (Android 4.1.2). There is where I see the "App was interrupted" message. Can I view the logs in the device? How Is this possible? Or by saying monitor the logs you mean with logcat? Why isn't it reaching the Application_Error event in the Starter service?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I am not using B4A-Bridge. I compile and install. I will try it to install the B4A-Bridge app and come back to you...

Hard to say without first understanding what happens.

Is it possible that it does not get to the Application_Error Sub in Starter service because I return true and the execution breaks? Or it does not enter at all the Application_Error Sub?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Perfect Erel. The B4A-Bridge saved me. I found the errors in the second service and corrected them. I also corrected the error in the Application_Error event which was that the logs stringbuilder was not initialized and it was getting in the Application_Error sub but the execution was breaking there because of the error. Now it works perfect. Thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…