Android Toast Messages not working

Viewed 32157

I'm developing a game via Andengine for Android. I have MainActivity class and GameScene class. I use Toast messages in GameActivity. And it is working.

Toast.makeText(this, " Hello World", Toast.LENGTH_SHORT).show();

So I wanna use Toast messages in GameScene class. But it doesn't work. Here is the code:

Toast.makeText(activity, " Hello World", Toast.LENGTH_SHORT).show();

I have to use "activity" instead of "this". But it doesn't work

why?

EDITED:

when I use second one, an error occurs. LogCat: http://s29.postimg.org/k8faj9mdj/Capture.png

9 Answers

Make sure the app you are testing has notifications turned on. That was my story and why toasts weren't working either. I had gone looking for a straight answer and it just happens that toasts are considered part of the notifications. Interesting stuff, I had no clue.

If you think your code is correct, try to close your emulator tab then open AVD manager, next wipe data, then restart. Or you can delete the current AVD and add a new one.

Related