Search code examples
javaandroidtoast

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?


Solution

  • 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).