Android Question RuntimeException: onStartCommand

FrankBerra

Active Member
Licensed User
Hello everyone,
i am receiving on Play developer console some random errors like this:

B4X:
java.lang.RuntimeException:
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4080)
  at android.app.ActivityThread.access$2400(ActivityThread.java:222)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1898)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:158)
  at android.app.ActivityThread.main(ActivityThread.java:7229)
  at java.lang.reflect.Method.invoke(Native Method:0)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.RuntimeException:
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:216)
  at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
  at test.app.check.handleStart(check.java:102)
  at test.app.check.onStartCommand(check.java:70)
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4063)

I noticed that some users rised this exception 2-3 times in a row and so the OS stopped the app services to start again (and the app became useless!)

As i can see it seems it is raised while starting the service "check".

I suppose that these crashes happen when user removes the app from the recent apps list.
In that case i used the sub Service_TaskRemoved in Starter service like this:

B4X:
Sub Service_TaskRemoved
    StartService("")
    StartService(Radar)
End Sub

The service Radar starts also the "check" service.

After receiving too many crashes i am wondering which is the best method to keep all the services running even if the user removes the app from recent app list.
And also is there a way to avoid/catch crashes on service start? Should i use Try-Catch?

The service "check" also contains some broadcast receivers. Is it possible that the crashes are rised while the service is called from an event that needs the receiver but the service for some reasons it is not ready/started?


Thanks in advance for your help
 
Last edited:

FrankBerra

Active Member
Licensed User
I have also decompiled the APK and found the two Subs but nothing useful for me.

Sub handleStart:
B4X:
private void handleStart(Intent paramIntent)
  {
    BA.LogInfo("** Service (check) Start **");
    Method localMethod = (Method)processBA.htSubs.get("service_start");
    IntentWrapper localIntentWrapper;
    if (localMethod != null)
    {
      if (localMethod.getParameterTypes().length <= 0) {
        break label98;
      }
      localIntentWrapper = new IntentWrapper();
      if (paramIntent != null)
      {
        if (!paramIntent.hasExtra("b4a_internal_intent")) {
          break label90;
        }
        localIntentWrapper.setObject((Intent)paramIntent.getParcelableExtra("b4a_internal_intent"));
      }
    }
    for (;;)
    {
      processBA.raiseEvent(null, "service_start", new Object[] { localIntentWrapper });
      return;
      label90:
      localIntentWrapper.setObject(paramIntent);
    }
    label98:
    processBA.raiseEvent(null, "service_start", new Object[0]);
  }

Sub OnStartCommand:
B4X:
public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2)
  {
    if (ServiceHelper.StarterHelper.onStartCommand(processBA)) {
      handleStart(paramIntent);
    }
    for (;;)
    {
      BA localBA = processBA;
      Object[] arrayOfObject = new Object[3];
      arrayOfObject[0] = paramIntent;
      arrayOfObject[1] = Integer.valueOf(paramInt1);
      arrayOfObject[2] = Integer.valueOf(paramInt2);
      localBA.runHook("onstartcommand", this, arrayOfObject);
      return 2;
      ServiceHelper.StarterHelper.waitForLayout = new check.1(this, paramIntent);
    }
  }
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
In that case i used the sub Service_TaskRemoved in Starter service like this
When TaskRemoved is reached, you don't have to restart the Starter service. It will be started when Radar will start.
So, please try removing the call to it
B4X:
StartService("")
Secondly, you could try adding a delay to restart Radar
B4X:
StartServiceAtExact(Radar,DateTime.Now+DateTime.TicksPerSecond,True)
 
Upvote 0

FrankBerra

Active Member
Licensed User
Even putting a delay to restart the service Radar (that starts the service check) doesn't solve the problem.
I am still receiving random crashes as the first post.
Probably the error it is not related to sub Service_TaskRemoved

Anyone that can understand what that crash report means?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Yes it is.
I am still receiving similar errors like this:
B4X:
java.lang.RuntimeException: 
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3468)
  at android.app.ActivityThread.-wrap21(ActivityThread.java:0)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1632)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6290)
  at java.lang.reflect.Method.invoke(Native Method:0)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.RuntimeException: 
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
  at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
  at test.app.check.handleStart(check.java:105)
  at test.app.check.access$000(check.java:8)
  at test.app.check$1.run(check.java:70)
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:105)
  at test.app.check.onStartCommand(check.java:68)
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3451)
 
Upvote 0
Top