Summary:
In a B4A class, I need a Sub to execute, among other instructions, Sleep() and then a Wait For (a long task), but subsequent lines of code are never executed; removing the Sleep() is not an option (doing so, instructions are executed as expected).
Reproduction Steps:
==================
Waiting for LongTask
C Started
C Done
Expected Behavior:
==================
Waiting for LongTask
C Started
C Done
*** Use Successfull ***
- Notes: Issue occurs on real device (Redmi Note 8 Pro - Android 11) and emulator (Platform_30_google_apis_playstore). I don't attach original code, it is more complex and part of a bigger project, so I just recreate the issue with a minimal number of lines of code
- Additional information: Putting the Sub in Activity ad calling it, it works. Using same class in B4J, code executed as expected (no bugs).
In a B4A class, I need a Sub to execute, among other instructions, Sleep() and then a Wait For (a long task), but subsequent lines of code are never executed; removing the Sleep() is not an option (doing so, instructions are executed as expected).
Reproduction Steps:
- Install and launch B4A version (12.50)
- Set path to jdk-1.8\bin\javac.exe (also tried jdk-17.0.5 and jdk-19.0.2)
- Set path to android-33\android.jar (also tried android-33)
- Open the project in attached zip (or copy and paste following code in a Default New Project, adding a second button to Layout.bal)
- Compile and run the project
- Observe output in log window after pressing either button
==================
Waiting for LongTask
C Started
C Done
Expected Behavior:
==================
Waiting for LongTask
C Started
C Done
*** Use Successfull ***
- Notes: Issue occurs on real device (Redmi Note 8 Pro - Android 11) and emulator (Platform_30_google_apis_playstore). I don't attach original code, it is more complex and part of a bigger project, so I just recreate the issue with a minimal number of lines of code
- Additional information: Putting the Sub in Activity ad calling it, it works. Using same class in B4J, code executed as expected (no bugs).
Main:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#BridgeLogger: True
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim bug As ReproduceBug
End Sub
Sub Activity_Create(FirstTime As Boolean)
bug.Initialize
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
bug.Use(False)
xui.MsgboxAsync("Hello world!", "B4X")
Log("==================")
End Sub
Sub Button2_Click
bug.Use(True)
xui.MsgboxAsync("Hello world!", "B4X")
Log("==================")
End Sub
ReproduceBug.bas:
Sub Class_Globals
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Public Sub Use (sleeping As Boolean)
If sleeping Then
Sleep(0)
End If
Log("Waiting for LongTask")
Wait For (LongTask) Complete (success As Boolean)
'Bug: if sleeping = True, following code wont execute
If success Then
Log("*** Use Successfull ***")
Else
Log("*** Use Failed ***")
End If
End Sub
Private Sub LongTask () As ResumableSub
Log("C Started")
Sleep(100)
Log("C Done")
Return True
End Sub