-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadActivity.kt
43 lines (33 loc) · 1.08 KB
/
ThreadActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.example.myapplication
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class ThreadActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_thread)
val runnable : Runnable = object : Runnable {
override fun run() {
Log.d("thread-1", "Thread1 is made")
}
}
val thread : Thread = Thread(runnable)
val button : Button = findViewById(R.id.button)
button.setOnClickListener {
thread.start()
}
Thread(object : Runnable {
override fun run() {
Log.d("thread-1", "Thread2 is made")
}
}).start()
Thread(Runnable {
Thread.sleep(2000)
Log.d("thread-1", "Thread3 is made")
runOnUiThread{
button.setBackgroundColor(getColor(R.color.textview_color))
}
}).start()
}
}