Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dispatch(private val label: String = "main") {
- var handler: Handler? = null
- var handlerThread: HandlerThread? = null
- init {
- if (label == "main") {
- handlerThread = null
- handler = Handler(Looper.getMainLooper())
- } else {
- handlerThread = HandlerThread(label)
- handlerThread!!.start()
- handler = Handler(handlerThread!!.looper)
- }
- }
- fun getSomething(forceNetwork: Boolean ) {
- val queue1 = Dispatch("thread1") // Create a thread called "thread1"
- queue1.async {
- for (i in 0..2_000_000) {
- print("Hello World")
- // Do everything i want in the current thread
- }
- // And on the main thread I call my callback
- Dispatch.main.async {
- //callback?.invoke(.........)
- }
- }
- }
- val button = findViewById<Button>(R.id.button)
- button.setOnClickListener {
- DataManager.getTickets(true)
- }
- val button2 = findViewById<Button>(R.id.button2)
- button2.setOnClickListener {
- val intent = Intent(this, Test::class.java) // Switch to my Test Controller
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
- startActivity(intent)
- finish()
- }
Add Comment
Please, Sign In to add comment