Accessing UI thread handler from a service

后端 未结 7 1499
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 11:57

I am trying some thing new on Android for which I need to access the handler of the UI thread.

I know the following:

  1. The UI thread has its own handler
相关标签:
7条回答
  • 2020-11-27 12:48

    In kotlin thats how you can do it

    Let say if you want to show Toast message from service

    val handler = Handler(Looper.getMainLooper())
    handler.post {
       Toast.makeText(context, "This is my message",Toast.LENGTH_LONG).show()
    }
    
    0 讨论(0)
提交回复
热议问题