Guest User

Untitled

a guest
Apr 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. class Dispatch(private val label: String = "main") {
  2.  
  3. var handler: Handler? = null
  4. var handlerThread: HandlerThread? = null
  5.  
  6. init {
  7. if (label == "main") {
  8. handlerThread = null
  9. handler = Handler(Looper.getMainLooper())
  10. } else {
  11. handlerThread = HandlerThread(label)
  12. handlerThread!!.start()
  13. handler = Handler(handlerThread!!.looper)
  14. }
  15. }
  16.  
  17. fun getSomething(forceNetwork: Boolean ) {
  18.  
  19. val queue1 = Dispatch("thread1") // Create a thread called "thread1"
  20. queue1.async {
  21. for (i in 0..2_000_000) {
  22. print("Hello World")
  23. // Do everything i want in the current thread
  24. }
  25.  
  26. // And on the main thread I call my callback
  27. Dispatch.main.async {
  28. //callback?.invoke(.........)
  29. }
  30. }
  31. }
  32.  
  33. val button = findViewById<Button>(R.id.button)
  34. button.setOnClickListener {
  35. DataManager.getTickets(true)
  36. }
  37.  
  38.  
  39. val button2 = findViewById<Button>(R.id.button2)
  40. button2.setOnClickListener {
  41. val intent = Intent(this, Test::class.java) // Switch to my Test Controller
  42. intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
  43. startActivity(intent)
  44. finish()
  45. }
Add Comment
Please, Sign In to add comment