Toast的显示需要的环境

来源:互联网 发布:oracle数据库发展历史 编辑:程序博客网 时间:2024/06/05 16:31

   A toast can be created and displayed from an Activity or Service. If you create a toast notification from a Service,it appears in front of the Activity currently in focus.


API 解释

我们调用toast.makeText时所传入的context对象必须是一个activity或者service类型的。当然也可以是getApplicationContext,因为他的生命周期是整个APP运行过程,而且toast显示必须是在有activity在前台显示的情况下,而且必须是在主线程下面才能运行,因为他和消息机制有关系,普通的Handler无法接收到,必须传入Looper.getMainLooper.


0 0
原创粉丝点击