Android Service to show toast

后端 未结 3 1167
-上瘾入骨i
-上瘾入骨i 2020-12-09 00:55

This code is supposed to use a service to show a toast message. There are no errors, but it doesn\'t show the toast.

main activity

public class Main         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 01:32

    See this part of the docs

    (An IntentService has a few limitations:

    It can't interact directly with your user interface. To put its results in the UI, you have to send them to an Activity.

    You need to put it on the main Thread. See the answer here by rony of a way to do that.

    and from the full documentation on IntentService

    handles each Intent in turn using a worker thread

提交回复
热议问题