Android Question Wait for Msgbox_results - resumable sub error

Nokia

Active Member
Licensed User
Longtime User
what the best way to use Wait for Msgbox with out getting a resumable sub error?

B4X:
'some code before msgbox'

        Dim message, title As String
        Dim result As Int
        
        title = "Title"
        message = "Message"
        Dim icon As Bitmap = LoadBitmap(File.DirAssets, "Question.png")
        Msgbox2Async(message, title, "Yes", "No", "", icon, False)
        Wait For Msgbox_Result (result As Int)
        
        If result = DialogResponse.POSITIVE Then
            If File.Delete(Main.strMMDirLoc, FileName) = True Then
                bWriteFile = True
            Else
                bWriteFile = False
            End If
        End If
        
'other code to execute here'
 

JohnC

Expert
Licensed User
Longtime User
It seems like you are using it correctly, so if you are getting an error it probably is being caused by some conflict with the code before or after this code.

Please post the events from the log window so we can see more details.
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
It seems like you are using it correctly, so if you are getting an error it probably is being caused by some conflict with the code before or after this code.

Please post the events from the log window so we can see more details.


well when I use the code this way...

B4X:
result = Msgbox2Async(message, title, "Yes", "No", "", icon, False)

I get this error:

Error occurred on line: 93 (actKeyImport)
java.lang.NumberFormatException: For input string: "android.app.AlertDialog@660504"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:667)
at b4a.SecureShareMobile.actkeyimport._importmmk(actkeyimport.java:613)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7866)
at android.widget.TextView.performClick(TextView.java:14956)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7811)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
It seems like you are using it correctly, so if you are getting an error it probably is being caused by some conflict with the code before or after this code.

Please post the events from the log window so we can see more details.

I also get the error of Resumable subs return type must be ResumableSub, but my sub returns boolean...
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
That error is expected because that is not the way to use Msgbox2Async.

Your first post is doing it right - do you get an error with the first method?
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I also get the error of Resumable subs return type must be ResumableSub, but my sub returns boolean...
You should show your Sub.
To return a value it should be like this
B4X:
Sub Name (myvariable as Int) as Resumablesub
 
Upvote 0

Nokia

Active Member
Licensed User
Longtime User
That error is expected because that is not the way to use Msgbox2Async.

Your first post is doing it right - do you get an error with the first method?

yes it says I need to return an Resumablesub variable....

it will not pass back the boolean varaiable...
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
See this tutorial on how to make a resumable sub return a value:

 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
B4X:
Wait For(MyResult) Complete (Result As Boolean)
Log("HI! I am " & Result)


Sub MyResult As ResumableSub
    Return True
End Sub
 
Last edited:
Upvote 0
Top