Android Question ResumableSub in DoWhile loop allowed?

fredo

Well-Known Member
Licensed User
Longtime User
Since ResumableSubs have so many advantages we have reworked a large project completely.

One function raised this error:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.


Some more details:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main$ResumableSub_test2resume (java line: 459)
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
    at android.view.InputChannel.nativeReadFromParcel(Native Method)
    at android.view.InputChannel.readFromParcel(InputChannel.java:148)
    at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:759)
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:531)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
    at android.app.Dialog.show(Dialog.java:319)
    at anywheresoftware.b4a.keywords.Common.showAndTrackDialog(Common.java:580)
    at anywheresoftware.b4a.keywords.Common.InputListAsync(Common.java:559)
    at b4a.example.main$ResumableSub_test2.resume(main.java:459)
    at b4a.example.main._v0(main.java:433)
    at b4a.example.main$ResumableSub_test1.resume(main.java:410)
    at b4a.example.main._v5(main.java:389)
    at b4a.example.main._activity_resume(main.java:349)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at b4a.example.main.afterFirstLayout(main.java:108)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

24-08-_2017_09-25-06.png


This is the neutralized excerpt from the project:

B4X:
Sub Process_Globals
    Private pgstrColor As String = ""
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Resume
    Dim bolRepeat As Boolean = True   
    Do While bolRepeat
        test1
        If pgstrColor = "Red" Then
            bolRepeat = False
        End If
    Loop
    Log(">>end")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub test1
    wait for(test2) complete(strResult As String)
    Log("  test1.Selected color: " & strResult)
    pgstrColor = strResult
End Sub

Sub test2 As ResumableSub
    Dim options As List = Array("Red", "Green", "Blue")

    InputListAsync(options, "Select Color", 0, False)
    Wait For InputList_Result (Index As Int)  ' <<<<<<<<<<<<<<<<<

    If Index <> DialogResponse.CANCEL Then
        Return options.Get(Index)
    Else
        Return ""
    End If
End Sub

Do I use the ResumableSubs correctly?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The answer to the question in the title is yes. You can use resumable subs in loops.

You must use the new ResumableSub type if you want to wait for a resumable sub to complete. Your current code will create many dialogs.

Correct code:
B4X:
Do While bolRepeat
 Wait For (test1) Complete (Result As Object) 
 ...
Loop

B4X:
Sub test1 As ResumableSub
 ...
 Return Null
End Sub
 
Upvote 0
Top