Android Question alternative to sleep ?

Hirogens

Active Member
Licensed User
Longtime User
Hello, I prefer to say it now: I will have a lot of questions
I have just finish my project (I recreate DFU OTA)
Now I would like to perform the code and try to avoid some problem. That's why I would like to know if an alternative to sleep exist.

Because when I use the sleep function, I think some process continue to run, and I would like something which put everything in pause.
thanks !
 

Hirogens

Active Member
Licensed User
Longtime User
Hum I use Sleep only to wait informations: for example I send a command to my device (Create objet), when the objet is create I receive information about this command (01 to success and other for an echec). I can't send information while I haven't my objet correctly create. So I use Sleep to wait this. It's work but not perfectly that's why I would like something to do nothing while I haven't receive the information.

I don't know if I do something like this it can work
B4X:
boolean = false
send_command_create
While boolean = false{}
When I have response from the device an event is reach and I can see if the command is success and then set this boolean to false
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
It seems to me the question is not about Sleep / Wait For as it is.

I would like something which put everything in pause

It's enough typical situation, when an app sends a request to server and waits a reply. During waiting time user's activity is undesirable.
Something similar modal Msgbox.

Well, it's relatively simple to prevent user's activity (WindowManager.LayoutParams) and screen rotation (ActivityInfo).
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Don't add complicated ways just for a wait. Mostly it's enough to disable some views and post a message like "Please wait". On the other hand a server's response takes some milliseconds so there isn't a problem at all.
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Hello
I don't know if resumable subs can help me: I send a command to my starter.
B4X:
CallSub(Starter, "recup_info_object")
and this is the function in my starter
B4X:
Public Sub recup_info_object
    ManagerD.WriteData("0000fe59-0000-1000-8000-00805f9b34fb", "8ec90001-f315-4f60-9fb8-838830daea50", Array As Byte(0x06,0x01))
End Sub

This command send to my device an instruction. When the device send to me the information that I ask this function
B4X:
Sub Manager_DataAvailable (Services As String, Characteristics As Map)
    CallSub3(Main, "DataAvailable", Services, Characteristics)
End Sub
handle the response, and in my main I treate the informations. If my command is a success I can continue the code. I have a lot of command like this and that's why I need to be sure to handle the response everytime.
I don't know if it can help you more :/
Maybe you're right with resumable subs but maybe there is an other option =)
Thanks !
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…