I know there are some other issues regard this problem, however, mine is surprisingly different (at least I think so).
I guess my code is right but I don't have idea why toast message doesn't display. Firstly, I couldn't see toast message in my Fragments. Then I decided to put it in my activity and amazingly it doesn't display here too.
This is code of my Activity which has been extended from FragmentActivity.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d(TAG, "***************************");
Log.d(TAG, "*** Application started ***");
Log.d(TAG, "***************************");
// assign layout to activity
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
Toast.makeText(mContext, "Hello World", Toast.LENGTH_SHORT).show();
.
.
.
}
Application works fine without error and just this f.toast message doesn't display! I even replaced mContext with getApplicationContext() and I had same result, toast does not display.
Any suggestion would be appreciated. Thanks
===============
Update: When I open Toast class there are some red lines. please look at image below
The most important one , make sure your Android Notifications are on for your app, else the Toast will not be shown.
Display the created Toast Message using the show() method of the Toast class. The code to show the Toast message: Toast. makeText(getApplicationContext(), "This a toast message", Toast.
You're trying to display a Toast in a background thread. You should do all your UI operations on the main UI thread. The exception RuntimeException: Can't create handler inside thread that has not called Looper. prepare() can be a little cryptic for beginners but essentially it tells you that you're in a wrong thread.
A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.
Perhaps you have accidentially disabled notifications for your app in the settings? This causes no toasts too.
something may be hiding your toast...so I use this when that appears to be the case:
Toast toast = Toast.makeText(TaskEdit.this, "Task Saved", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
toast.show();
You can change the position of the toast location using the various setGravity options available. Happy Coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With