You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are running it all from UI thread, then it is quite easy via a bit of abstraction. You should just introduce a function to restart your coroutine. Select the block of code that is to the right of send_udp_repeat and press (Ctrl/Cmd-Shfit-M) to introduce a function:
fun launchSendUpdRepeat() = launch(CommonPool) {
var nextPrintTime = System.currentTimeMillis()
while (isActive) {
val currentTime = System.currentTimeMillis()
if (currentTime >= nextPrintTime) {
sendUDPrequest(UDP_SERVER_IP, UDP_SERVER_PORT, UDP_SERVER_MSG)
nextPrintTime = currentTime + 2000L
}
}
}
send_udp_repeat = launchSendUdpRepeat()
Then change send_udp_repeat to a nullable type and rewrite your click listeners (note that you don't have to check for isActive):
After cancel job, how can I restart?
This is my code. (kotlin)
The text was updated successfully, but these errors were encountered: