Android Question SLEEP on B4A 6.5

Star-Dust

Expert
Licensed User
Longtime User
Is it possible to use sleep commands with B4A 6.5?

I saw following a @Erel thread that used this code to intercept errors in the servicer Starter (Application_Error)

B4X:
Dim jo As JavaObject
Dim l As Long = 500
jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))

Does it correspond to B4A 7 sleep?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Short but eloquent answer :p:p:p:p
Thank's
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Many thanks, now I understand the difference.

To create pauses, I could use java.lang.Thread.sleep instead of DoEvents in B4A 6.5 so I can be compatible with B4A 7 (where DoEvents is deprecated)?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I know I'm not the same. In my code use DoEvents to create pauses (Type Delay (500)). I would avoid DoEvents because it was deprecated in version 7, so the code could be used by both versions. So java.lang.Thread.sleep could do my job
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Reading the posts of @Erel where it explains the resume sub, I understand the commands of Sleep and Wait for version 7. Before I knew their functions well. Certainly for me that I started to use in Turbo Pascal a concept is a bit difficult to digest
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I wanted to replace this

B4X:
Sub Delay(Time as int)
  Dim Now as Long = DateTime.Now

  while Datetime.Now<=Now+Time
  DoEvents
  Loop

End Sub

With
B4X:
Sub Delay(Time as Long)
  Dim jo As JavaObject
  jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(Time))
End Sub
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
What are you using this Delay for?

You can probably switch to CallSubPlus. This is a better solution.
Ok, Thank's. Try it
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0
Top