Lee Gillie CCP Active Member Licensed User Longtime User Nov 11, 2015 #1 Running v5.50 release. I renamed an existing service module to be "Starter". Change the file name on-disk. Open B4A, it complains it can't find old module. I add existing, the renamed file. It loads... all this is fine. I added to service attributes Code: #Region Service Attributes #StartAtBoot: False #ExcludeFromLibrary: True #End Region In starter I have.... Code: Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. ETC.... End Sub Sub Service_Create Log("at Starter.Service_Create") ETC.... End Sub Sub Service_Start (StartingIntent As Intent) Log("at Starter.Service_Start") logcat.LogCatStart(Array As String(),"logcat") 'lower cased module name NativeMe.InitializeStatic(Application.PackageName & ".starter") End Sub Sub Service_Destroy Log("at Starter.Service_Destroy") ETC......... 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 Log("at Starter.Application_Error") ETC.... Return True End Sub In the MAIN activity I have a button handler.... Code: Sub btnTest_Click Log("at Main.btnTest_Click") Dim i As Int i = "sdf" End Sub ok, so then to test. I tried with debug build, and it did not invoke the error handler. In the fog I call my head, I recall something about needing to run a release build, but that also made no difference. In the logcat I can confirm the Application_Error was not called (no logged message). But I do see a pop-up from Android saying the app has stopped. Here is what I see in logcat... PackageAdded: packagedp.eljaydelivery etc. at Starter.Service_Create etc. at Starter.Service_Start etc. at Main.Activity_Create etc. at Main.Activity_Resume etc. at Starter.Service_Destroy etc. at Main.btnTest_Click main_btntest_click (java line: 529) java.lang.NumberFormatException: Invalid double: "sdf" etc. main_btntest_click (java line: 529) java.lang.NumberFormatException: Invalid double: "sdf" etc. Click to expand... I don't ever see the log entry from Application_Error Perhaps the way I renamed this service module to Starter, rather than creating one from scratch is at issue? I was under the impression the module name alone was all that was needed. Perhaps it doesn't catch the kind of exception I forced?
Running v5.50 release. I renamed an existing service module to be "Starter". Change the file name on-disk. Open B4A, it complains it can't find old module. I add existing, the renamed file. It loads... all this is fine. I added to service attributes Code: #Region Service Attributes #StartAtBoot: False #ExcludeFromLibrary: True #End Region In starter I have.... Code: Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. ETC.... End Sub Sub Service_Create Log("at Starter.Service_Create") ETC.... End Sub Sub Service_Start (StartingIntent As Intent) Log("at Starter.Service_Start") logcat.LogCatStart(Array As String(),"logcat") 'lower cased module name NativeMe.InitializeStatic(Application.PackageName & ".starter") End Sub Sub Service_Destroy Log("at Starter.Service_Destroy") ETC......... 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 Log("at Starter.Application_Error") ETC.... Return True End Sub In the MAIN activity I have a button handler.... Code: Sub btnTest_Click Log("at Main.btnTest_Click") Dim i As Int i = "sdf" End Sub ok, so then to test. I tried with debug build, and it did not invoke the error handler. In the fog I call my head, I recall something about needing to run a release build, but that also made no difference. In the logcat I can confirm the Application_Error was not called (no logged message). But I do see a pop-up from Android saying the app has stopped. Here is what I see in logcat... PackageAdded: packagedp.eljaydelivery etc. at Starter.Service_Create etc. at Starter.Service_Start etc. at Main.Activity_Create etc. at Main.Activity_Resume etc. at Starter.Service_Destroy etc. at Main.btnTest_Click main_btntest_click (java line: 529) java.lang.NumberFormatException: Invalid double: "sdf" etc. main_btntest_click (java line: 529) java.lang.NumberFormatException: Invalid double: "sdf" etc. Click to expand... I don't ever see the log entry from Application_Error Perhaps the way I renamed this service module to Starter, rather than creating one from scratch is at issue? I was under the impression the module name alone was all that was needed. Perhaps it doesn't catch the kind of exception I forced?
Erel B4X founder Staff member Licensed User Longtime User Nov 12, 2015 #2 Lee Gillie CCP said: Perhaps the way I renamed this service module to Starter, rather than creating one from scratch is at issue? Click to expand... No. This is not the source of this issue. Are you connected with B4A-Bridge or USB debug mode? Upvote 0
Lee Gillie CCP said: Perhaps the way I renamed this service module to Starter, rather than creating one from scratch is at issue? Click to expand... No. This is not the source of this issue. Are you connected with B4A-Bridge or USB debug mode?
Lee Gillie CCP Active Member Licensed User Longtime User Nov 12, 2015 #3 I've used both, but I verified this morning that a release build running without either bridge or ADB/USB connection also apparently does not fire the event either. Upvote 0
I've used both, but I verified this morning that a release build running without either bridge or ADB/USB connection also apparently does not fire the event either.
Erel B4X founder Staff member Licensed User Longtime User Nov 12, 2015 #4 A toast message is better to test this. Please try to reproduce it in a small example and upload it. Upvote 0
Lee Gillie CCP Active Member Licensed User Longtime User Nov 13, 2015 #5 This small example illustrates the issue. I can run it from a release build, without the debugger. i.e. start from the tablet's app icon, and it does not catch the crash. At least I see no toast from the error handler. This behaves much as my main production project. Except in the production project, from time to time, I also see the Service_Destroy being called soon after the main activity starts. But I don't want to cloud the issue for this isolated question about getting Application_Error to fire. I am testing on a Samsung Galaxy Note 2014 Edition 10.1" (SM-P600) It is running Android version 4.4.2 Attachments StarterServiceTest.zip StarterServiceTest.zip 362.7 KB · Views: 549 Upvote 0
This small example illustrates the issue. I can run it from a release build, without the debugger. i.e. start from the tablet's app icon, and it does not catch the crash. At least I see no toast from the error handler. This behaves much as my main production project. Except in the production project, from time to time, I also see the Service_Destroy being called soon after the main activity starts. But I don't want to cloud the issue for this isolated question about getting Application_Error to fire. I am testing on a Samsung Galaxy Note 2014 Edition 10.1" (SM-P600) It is running Android version 4.4.2
Erel B4X founder Staff member Licensed User Longtime User Nov 15, 2015 #6 Please use File - Export as zip when uploading files. The sub is called. It was a wrong suggestion to use a toast as the toast message is removed when the process is killed. If you use USB debug mode then you will be able to see the logs when the app crashes. You can test it with a notification instead: Code: Sub Application_Error (Error As Exception, StackTrace As String) As Boolean Dim n As Notification n.Initialize n.Icon = "icon" n.SetInfo("App crashed", StackTrace, Main) n.Notify(1) Return True End Sub Upvote 0
Please use File - Export as zip when uploading files. The sub is called. It was a wrong suggestion to use a toast as the toast message is removed when the process is killed. If you use USB debug mode then you will be able to see the logs when the app crashes. You can test it with a notification instead: Code: Sub Application_Error (Error As Exception, StackTrace As String) As Boolean Dim n As Notification n.Initialize n.Icon = "icon" n.SetInfo("App crashed", StackTrace, Main) n.Notify(1) Return True End Sub
Lee Gillie CCP Active Member Licensed User Longtime User Nov 18, 2015 #7 I got my little test app, swapping Notify for Toast to work. So back to my big production app... I'm new to Starter services. I used a service previously, but the main app controlled it's lifetime. I used it to tap into the LOGCAT stream. What I observe is that the Application_Error is NOT fired. But I see that the Service_Destroyed event of the starter service is seen to occur early, prior to the induced error. I'm reasonably certain Application_Error will not execute without the starter service running. I think this will be for me to work through here. But I've been banging my head for a few days trying to discover what causes my starter service to exit prematurely. Sequence is like... Starter.Service_Start Main.Activity_Create Main.Activity_Resume Starter.Service_Destroy httputils2service.Create httputils2service.Start httputils2service.Start httputils2service.Start I tried block commenting out the entire body of main.Activity_Resume, but the starter service is still being destroyed. Such a puzzle?!?! Last edited: Nov 18, 2015 Upvote 0
I got my little test app, swapping Notify for Toast to work. So back to my big production app... I'm new to Starter services. I used a service previously, but the main app controlled it's lifetime. I used it to tap into the LOGCAT stream. What I observe is that the Application_Error is NOT fired. But I see that the Service_Destroyed event of the starter service is seen to occur early, prior to the induced error. I'm reasonably certain Application_Error will not execute without the starter service running. I think this will be for me to work through here. But I've been banging my head for a few days trying to discover what causes my starter service to exit prematurely. Sequence is like... Starter.Service_Start Main.Activity_Create Main.Activity_Resume Starter.Service_Destroy httputils2service.Create httputils2service.Start httputils2service.Start httputils2service.Start I tried block commenting out the entire body of main.Activity_Resume, but the starter service is still being destroyed. Such a puzzle?!?!
Erel B4X founder Staff member Licensed User Longtime User Nov 19, 2015 #8 The starter service will only be destroyed if you call StopService somewhere. Upvote 0
Lee Gillie CCP Active Member Licensed User Longtime User Nov 20, 2015 #9 Ok... I see this now, you are right. The thing tripping me up is attempting to manage shutdown of the starter service in all scenarios. Somewhere on forums I saw the advice to put the StopService in Main activity pause event, but that may kill it prematurely. I have several activities. Another approach I tried is to tap into the cyclic activity of my starter service which collects logcat, and if all activities are paused, to consider it time to shut down the Starter service. I built a list of all modules, looking for any non-paused activity: Code: Sub IsAnyActivityRunning As Boolean For Each module As Object In activities If IsPaused(module) = False Then Return True Next Return False End Sub But this does not produce a correct result either. My starter service is 1) collecting logcat, and 2) providing an Application_Error handler. There is yet another issue, but I will post to a separate thread. Upvote 0
Ok... I see this now, you are right. The thing tripping me up is attempting to manage shutdown of the starter service in all scenarios. Somewhere on forums I saw the advice to put the StopService in Main activity pause event, but that may kill it prematurely. I have several activities. Another approach I tried is to tap into the cyclic activity of my starter service which collects logcat, and if all activities are paused, to consider it time to shut down the Starter service. I built a list of all modules, looking for any non-paused activity: Code: Sub IsAnyActivityRunning As Boolean For Each module As Object In activities If IsPaused(module) = False Then Return True Next Return False End Sub But this does not produce a correct result either. My starter service is 1) collecting logcat, and 2) providing an Application_Error handler. There is yet another issue, but I will post to a separate thread.
Erel B4X founder Staff member Licensed User Longtime User Nov 22, 2015 #10 Why do you want to stop it at all? Upvote 0
Lee Gillie CCP Active Member Licensed User Longtime User Nov 23, 2015 #11 There is no harm in it continuing to run. But I want to cease logcat collection, because the main app that is no longer running. Trying to be a good citizen of the battery. Upvote 0
There is no harm in it continuing to run. But I want to cease logcat collection, because the main app that is no longer running. Trying to be a good citizen of the battery.