Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Toast when I cant use "this" as context

I have a location listener activity and I want to make toast notifications. But it will not let me pass this as the context. How should I make toast work?

like image 666
Seth Hikari Avatar asked Apr 12 '11 20:04

Seth Hikari


People also ask

How do you pass the context in toast?

If the toast is located inside your activity class, you could use YourActiviy. this where YourActivity is the class name. If it's outside your class, you'll need to get your activity context (pass it in the constructor etc). Show activity on this post.


2 Answers

If the toast is located inside your activity class, you could use YourActiviy.this where YourActivity is the class name. If it's outside your class, you'll need to get your activity context (pass it in the constructor etc).

like image 161
MByD Avatar answered Oct 23 '22 12:10

MByD


If you are in the inner Class then try this also

getApplicationContext()

like image 29
droid kid Avatar answered Oct 23 '22 12:10

droid kid