Last active
April 10, 2019 21:41
-
-
Save featzima/64c3c5edabc64af158c3b5a4c4cd16ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CounterThread : Thread() { | |
private lateinit var handler: Handler | |
override fun run() { | |
Looper.prepare() | |
handler = object: Handler() { | |
private var counter = 100 | |
override fun handleMessage(msg: Message) { | |
counter += msg.arg1 | |
if (msg.arg1 == -1) handler.sendMessageDelayed(Message.obtain(msg), 1000) | |
Log.e("CounterThread", "$counter") | |
} | |
} | |
handler.sendMessage(Message().apply { arg1 = -1 }) | |
Looper.loop() | |
} | |
fun increment20() = handler.sendMessage(Message().apply { arg1 = 20 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment