Android Question Default Starter Service: Is It Really Needed

Mahares

Expert
Licensed User
Longtime User
In release mode, I have an app that does not have a starter service. I intentionally invoked a calculation that has a blank string. The error I got: java.lang.NumberFormatException: Invalid double: "" which is what it is supposed to show. That is fine and dandy.

I added the default starter service to it and compiled it again in release mode. The error I got : Unfortunately, B4A Example has stopped

It seems to me that the first compilation without the Starter service gave me a much better sense of what the error is than the one with the starter service. Can someone explain to me the advantage of a Default Starter service that everyone is bragging about. What is the advantage of having this sub as the only code in it:
B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
            Return True
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
The purporse of the Starter service is not to trap errors and debug your app, but...
a new feature named Starter service that provides a single and consistent entry point.
A place where you are sure that some process variables will be initialized.

What is the advantage of having this sub as the only code in it:
What should be the advantage to have Activity_Create, Activity_Resume, Activity_Paused as the only code inside them is... nothing?
They are special event routines and some of them receive a parameter; you have to write code inside them. It's almost like saying that it does not make sense to have For Next block, since there's nothing in it.


In release mode, I have an app that does not have a starter service. I intentionally invoked a calculation that has a blank string. The error I got: java.lang.NumberFormatException: Invalid double: "" which is what it is supposed to show. That is fine and dandy.

I added the default starter service to it and compiled it again in release mode. The error I got : Unfortunately, B4A Example has stopped

It seems to me that the first compilation without the Starter service gave me a much better sense of what the error is
Much better sense for you, developer, not for the user.
This is the best way to use the Application_Error event:
https://www.b4x.com/android/forum/threads/uncaught-exceptions.59805/
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The purporse of the Starter service is not to trap errors and debug your app, but...
I have specifically mentioned 'Default Starter' service. which is automatically created when you create a new app. All it has is the sub that I mentioned in post #1. I know that the starter service can be extremely beneficial in many situations, some of which you outlined. It is not useful in the scenario I described in my first post, because the error is more descriptive without it than with it. A great number of applications are created and the 'Default Starter' service is not touched or modified.
 
Last edited:
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
I have specifically mentioned 'Default Starter' service. which is automatically created when you create a new app. All it has is the sub that I mentioned in post #1. I know that the starter service can be extremely beneficial in many situations, some of which you outlined. It is not useful in the scenario I described in my first post, because the error is more descriptive without it than with it. A great number of applications are created and the 'Default Starter' service is not touched or modified.
You need to try catch then log the error or write it to a file. As my objects initialized in Starter are static I don't get errors like you describe. My sql and private classes I create are in it
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User

I have no dispute with or qualm about using a Starter service. In fact it is a good idea provided it has more code than the default line it has when it is automatically created. But if you have a starter service and you do not add any code to it, just because it was built in the app IDE when you create a new app is not beneficial; you are better off without it when you compile it in release mode. I see a great number of apps posted to the forum either requesting help or showcasing features have a starter service but the starter does not contain any code. Therefore in my opinion in this case, you are better off without it than with it. My example in post# 1 is case in point.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You can remove Application_Error and use the legacy and not recommended error handler.
I am sorry; I am not sure what your answer is telling me. I still do not understand the purpose of this sub in the starter service if it is the only code shown:
B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
            Return True
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can someone explain to me the advantage of a Default Starter service that everyone is bragging about.
There is more or less no relation between the starter service and the error handler. You can keep using the old and not recommended error handler by simply removing Application_Error sub.
You don't need to remove the starter service for this (though you can remove it if you like).

I explained in that tutorial the problems with the old handler:

1. The user cannot really know whether the program can continue correctly after the uncaught exception.
2. A crash report will not be sent to Google Play as the error was eventually caught internally.
3. It is inconsistent as the dialog only appears when the error happens with an activity context.
4. It was not possible to override this behavior and allow sending the error with an email for example.

As a developer you don't need this message as you can see the error in the logs.
Users will not be able to understand the error anyway.

However there is no point in arguing about it. Use whichever handler you like.
 
Upvote 0
Top