Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android findViewById in service

Tags:

android

I am doing something like when a service get started, a custom toast notification shows up.

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 ?

like image 646
user822211 Avatar asked Aug 09 '11 07:08

user822211


1 Answers

check this post

http://www.cloud208.com/blogica/Android+Custom+Toast+from+a+Service

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);
like image 53
Pratik Avatar answered Nov 28 '22 13:11

Pratik