Android Question ResumableSub into Starter Service crashes?

DavideV

Active Member
Licensed User
[SOLVED]
it was my mistake. the library Su was initialized under a conditional piece of code, so it was initialized only in some cases.
Moved Su.initialize in a different place and it works in starter service without problems!

---------------------------------------------------------------------------------------------------------


Hello B4A community,
I think I'm doing something wrong with a resumable sub.
I'm implementing a new piece of code In the starter service that make use of a resumable sub.
It works fine calling callsubdelayed(Starter,"checkRoot") from another activity, but crashes running it directly from Starter service.

I tried using callsubdelayed also from Starter or moving the call into the Service_start sub but crashes anyway.

B4X:
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
Sub Service_Create
    'various code here, already proven to work
    '....
 
    'check if rooted, this is a new piece of code that crashes the app:
    checkRoot
 
End Sub

'check if device is rooted
Sub checkRoot
    'check if rooted, if not then reset also the setting
    If Kvs.Get("superuser_enabled")=True Then Su.Initialize
    'new V5.11 (use updated Supersu library)
    Su.checkForRoot(Me,"RootCheck")
    Wait For (Su) RootCheck_Done(rootRes As Int)
    Select Case rootRes
        Case Su.ROOT_TRUE
            LogColor("Main> Device Rooted!", Colors.Green)
            Kvs.Put("superuser_enabled",True)
            General.newToastMessageShow(loc.localize("check_root_granted"),General.TOAST_INFO,Colors.LightGray)
        Case Else
            Kvs.Put("superuser_enabled",False)
            General.newToastMessageShow(loc.localize("check_root_not_granted"),General.TOAST_ERROR,Colors.LightGray)
    End Select
End Sub

The error is:

B4X:
*** Service (starter) Create ***
Device locale: it
** Service (starter) Start **
starter$ResumableSub_checkRootresume (java line: 305)
java.lang.NullPointerException: Attempt to read from field 'java.util.HashMap anywheresoftware.b4a.BA.htSubs' on a null object reference
    at anywheresoftware.b4a.agraham.threading.Threading.Start(Threading.java:205)
    at it.davidev.libs.superuser.superuser._checkforroot(superuser.java:121)
    at it.davidev.tagapplauncher.starter$ResumableSub_checkRoot.resume(starter.java:305)
    at it.davidev.tagapplauncher.starter._checkroot(starter.java:264)
    at it.davidev.tagapplauncher.starter._service_start(starter.java:549)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at it.davidev.tagapplauncher.starter.handleStart(starter.java:100)
    at it.davidev.tagapplauncher.starter.access$000(starter.java:8)
    at it.davidev.tagapplauncher.starter$1.run(starter.java:71)
    at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:221)
    at it.davidev.tagapplauncher.starter.onStartCommand(starter.java:69)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3366)
    at android.app.ActivityThread.-wrap21(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6236)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

Thanks in advance
Davide
 
Last edited:

DonManfred

Expert
Licensed User
i would run checkroot in service_start
Additionally i don´t see ou initialising kvs. Post an example project
 
Upvote 0

DavideV

Active Member
Licensed User
i would run checkroot in service_start
Additionally i don´t see ou initialising kvs. Post an example project
Hi Don,
as I wrote, it doesn't work from service_start, it crashes anyway...
KVs is initialized correctly, I removed it from the example as it has nothing to do with the problem. The sub works just fine when called from outside
 
Upvote 0

DavideV

Active Member
Licensed User
As you can see from the stack trace this library creates a new thread with the Threading library. It doesn't do it properly so you shouldn't use this library at all.
Yes, the library creates a new thread. But it works fine outside the Starter service...

Well, I'll move that check elsewhere :(
 
Upvote 0
Top