Issue
I am trying to update a seekbar every second in background using Kotlin & Coroutines but It says Handler() is deprecated use it with looper and i am confused how to use handler, looper and kotlin coroutines
The code i tried to make it work
val myHandler: Handler = Handler()
myHandler.postAtTime(asyncSeekBar(), 1000)
Here showing Handler() is deprecated
asyncSeekBar()
private fun asyncsSeekBar() {
CoroutineScope(Default).launch {
updateSeekBar()
}
}
but asyncSeekBar should be Runnable therefore showing and error
Type mismatch. Required: Runnable Found: Unit
If there is any other way of doing it with more simpler way, please suggest
Solution
You can use LifecycleScope
for this to run every second:
lifecycleScope.launch {
while (true) {
delay(1000)
updateSeekBar()
}
}
Answered By - Saurabh Thorat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.