Android Question returning ResumableSub from ResumableSub

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am converting one of my apps to use wait for / ResumableSub.

And I came across an interesting problem where I had routines returning a return

This is not the code but this is an easy way of showing:

B4X:
Sub Activity_Resume
    CallSubDelayed(Me, "TestResumableSub")
  
End Sub

Public  Sub TestResumableSub
            Log("TestResumableSub")
          
            Wait for (TestResumable2Sub) Complete(RC As Boolean)
End Sub

public     Sub TestResumable2Sub As ResumableSub
            Log("TestResumableSub2")
  
            Return TestResumableSub3
End Sub

public     Sub TestResumableSub3 As ResumableSub
            Log("TestResumableSub3")
  
            Return TestResumableSub4
End Sub

public     Sub TestResumableSub4 As ResumableSub
            Log("TestResumableSub4")
  
            Sleep(0)
          
            Return True
End Sub

The above generates this output and error

B4X:
** Activity (main) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
TestResumableSub
TestResumableSub2
TestResumableSub3
TestResumableSub4
main$ResumableSub_TestResumableSubresume (java line: 443)
java.lang.ClassCastException: anywheresoftware.b4a.keywords.Common$ResumableSubWrapper cannot be cast to java.lang.Boolean
    at b4a.example.main$ResumableSub_TestResumableSub.resume(main.java:443)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:190)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1761)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6939)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
** Activity (main) Pause, UserClosed = false **

Now I understand the problem
Wait for (TestResumable2Sub) Complete(RC As Boolean)
that I am not declaring the return type. And there are two fixes for this either I can change the RC as Boolean to RC as ResumableSub or
for each return I can do a wait for(x...) complete(RC as Boolean) and then return RC

I just found it surprising that returning a boolean that resumablesub could not propergate the return type backwards

BobVal
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
??Confused by your answer. Didn't say I know how to use it, but I came across this while doing a search and replace type of conversion to my code.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I guess what I should have said, is I would have thought that the compiler would have given me a warning on this rather then the program crashing
 
Upvote 0
Top