Android Question How to set a timer /sleep interval based on device speed

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hello guys,



I have an application that starts another application , waits for a few seconds and then call a function but the problem is that devices speeds are not the same
Is there a way that I make these seconds a variable based on device speed?


Regards
 

DonManfred

Expert
Licensed User
Longtime User
that starts another application
your app too?
and then call a function
call a function in your app? in the other app?
Is there a way that I make these seconds a variable based on device speed?
You can not expect every device running the same speed.

Adapt the time you wait. Make it more seconds until it works for all devices.

If you call your own app then you can use intents to communicate between the apps. This is probably the best solution as app A gets an intent if App B finishes his work.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
What you could also do is:

1) Have a variable called "FINISHED" and set it to "False"
2) Setup a timer for say 100 milliseconds. And when this timer triggers, it will set that variable for TRUE
3) Then run a do-while loop and have another variable "S" that counts up:

B4X:
S = 0
Do
    S = S + 1
Loop While Finished = False

This way after the timer ticks, the variable S will have a number in it that is proportional to the speed of the device.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
The issue is that speed is not a constant even for a single device as it depends what else it is doing, if memory is available, if some task is clogging the CPU, etc... So if I were to do this, either I would try to set a flag in the other app if you can, or just wait long enough, or allow the function to fail gracefully if the other app is not up and try again a littler while later.
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
That's right
The problem is that I don't have access to the other application and as the customer has decided to give it a static value , I will stop here :D
 
Upvote 0
Top