在服务机器人findViewById [英] Android findViewById in service
本文介绍了在服务机器人findViewById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做这样的事情,当一个服务开始,自定义Toast通知显示出来。
I am doing something like when a service get started, a custom toast notification shows up.
自定义吐司视图是在一个XML文件中定义,问题是, findViewById
是在服务类中没有提供。
The custom toast view is defined in a xml file, the problem is that findViewById
is not available in Service class.
由于这是一个坏主意,开始一个活动的服务。那么,如何才能解决这个问题?
Since it's a bad idea to start an activity in a service. So, how can i solve this problem ?
推荐答案
检查这个帖子
http://www.cloud208.com/blogica/安卓+自定义+面包+从+ A +服务
据该职位,你可以使用带有空
吹气作为第二个参数:
According to that post, you can use an inflater with null
as the second argument:
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_layout, null);
这篇关于在服务机器人findViewById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文