Reputation: 10296
I use this code in several places in my app:
Toast.makeText(getApplicationContext(), "toast", Toast.LENGTH_SHORT).show();
When running in the emulator they almost always show. The only times they don't show is when I'm debugging and take a long time to step through the code.
When I install the app on my device none of the Toasts work. I didn't notice at first but I realized that I've never once seen them popup on my device. Is that how Toasts work?
Edit: I have tried these two alternatives: Toast.makeText(this, "toast", Toast.LENGTH_SHORT).show(); Toast.makeText(ActivityName.this, "toast", Toast.LENGTH_SHORT).show();
Neither of these work. All toasts work in the emulator (2.2, 2.3, 4.1) but none work on my device (Galaxy Nexus 4.1).
Upvotes: 1
Views: 1681
Reputation: 121
I had this problem, and found out that I had set my app in the device settings to not show any notifications. After I allowed for notifications under the device settings, everything worked just fine.
Hopefully this will help some other poor soul not spend an afternoon finding the answer.
Upvotes: 10
Reputation: 34301
The line you wrote to show the Toast is 100% correct and toast should come up. There is no error in it.
Problem is in like, where you wrote those lines..!!
To know the actual problem one will need to check and debug
your entire code.
But while it comes to guessing the problem there may be,
You have put your Toast
in certain if..else
condition which is not getting true
Toast
in the part of code where the execution control don't go
String
variables appended with Toast
string and those variables are null
Just to check, replace your Toast
with Log
and see what happens.
Upvotes: 0